Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>10014 is <code>WSAEFAULT</code>, which means <code>recv()</code> is detecting that "the buf parameter is not completely contained in a valid part of the user address space.". That makes sense because you have a buffer overflow error in your code. You have allocated 4096 bytes on the call stack for your <code>req</code> buffer. Each time you call <code>get_req_tcp()</code>, you are telling it to read 4096 bytes, even if <code>req</code> does not actually have 4096 bytes available to read into.</p> <p>Each time your loop runs, you are telling <code>recv()</code> to read bytes into a new start position within the buffer, but you are not telling <code>recv()</code> how many bytes are remaining after that position, so the loop overflows the buffer and will eventually access a memory address that is not on the call stack, causing the <code>WSAEFAULT</code> error.</p> <p>You need to add an extra parameter to <code>get_req_tcp()</code> that tells it how many bytes to read.</p> <p>Try this:</p> <pre><code>DWORD WINAPI tcp_t(LPVOID lpParam) { SOCKET tcp_client_s = (SOCKET)lpParam; struct sockaddr_in tcp_client; int tcp_client_len = sizeof(tcp_client), length; char req[4096], resp[4096]; getpeername(tcp_client_s, (struct sockaddr *)&amp;tcp_client, &amp;tcp_client_len); cli_log(PROTO_TCP, LOG_SYS, "(%s:%d) TCP thread spawned\n", inet_ntoa(tcp_client.sin_addr), ntohs(tcp_client.sin_port)); length = get_req_tcp(tcp_client_s, req, sizeof(req), tcp_client); if (length &gt; 0) { while (!strstr(req, "\r\n\r\n")) { retval = get_req_tcp(tcp_client_s, req + length, sizeof(req) - length, tcp_client); if (retval &lt; 1) { length = 0; break; } length += retval; } if ((length &gt; 0) &amp;&amp; (strci(req, "GET /syachi2ds/web/", 0))) { length = check_req(req, resp); if (length &gt; 0) send_resp_tcp(tcp_client_s, resp, length, tcp_client); } } closesocket(tcp_client_s); cli_log(PROTO_TCP, LOG_SYS, "(%s:%d) socket closed, closing thread\n", inet_ntoa(tcp_client.sin_addr), ntohs(tcp_client.sin_port)); return 0; } int get_req_tcp(SOCKET in_s, char *buf, int buflen, struct sockaddr_in in) { cli_log(PROTO_TCP, LOG_COMM, "(%s:%d) waiting for incoming request...\n", inet_ntoa(in.sin_addr), ntohs(in.sin_port)); if ((!buf) || (buflen &lt; 1)) { cli_log(PROTO_TCP, LOG_ERROR, "invalid buffer passed for recv()\n"); return -1; } int retval = recv(in_s, buf, buflen, 0); if (retval == SOCKET_ERROR) { cli_log(PROTO_TCP, LOG_ERROR, "(%d) recv() failed\n", WSAGetLastError()); return -1; } if (retval == 0) { cli_log(PROTO_TCP, LOG_ERROR, "client disconnected\n"); return 0; } cli_log(PROTO_TCP, LOG_COMM, "(%s:%d) %d bytes received\n", retval, inet_ntoa(in.sin_addr), ntohs(in.sin_port)); return retval; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload