From: Fabian Keil Date: Sun, 2 Nov 2008 16:48:20 +0000 (+0000) Subject: Revert revision 1.195 and try again. X-Git-Tag: v_3_0_11~183 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=c5e10b38218aabd514001324c927e3a79d2593dd Revert revision 1.195 and try again. --- diff --git a/jcc.c b/jcc.c index 6641465f..4b71bccb 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.199 2008/10/26 15:36:10 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.200 2008/10/26 16:53:18 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.199 2008/10/26 15:36:10 fabiankeil Exp $" * * Revisions : * $Log: jcc.c,v $ + * Revision 1.200 2008/10/26 16:53:18 fabiankeil + * Fix gcc44 warning. + * * Revision 1.199 2008/10/26 15:36:10 fabiankeil * Remove two debug messages with LOG_LEVEL_INFO. * @@ -2065,6 +2068,28 @@ static int server_response_is_complete(struct client_state *csp, size_t content_ } #endif /* FEATURE_CONNECTION_KEEP_ALIVE */ +/********************************************************************* + * + * Function : mark_server_socket_tainted + * + * Description : Makes sure we don't reuse a server socket + * (if we didn't read everything the server sent + * us reusing the socket would lead to garbage). + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * + * Returns : void. + * + *********************************************************************/ +static void mark_server_socket_tainted(struct client_state *csp) +{ + if ((csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE)) + { + log_error(LOG_LEVEL_CONNECT, "Unsetting keep-alive flag."); + csp->flags &= ~CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE; + } +} /********************************************************************* * @@ -2575,7 +2600,8 @@ static void chat(struct client_state *csp) if (n < 0) { log_error(LOG_LEVEL_ERROR, "select() failed!: %E"); - break; + mark_server_socket_tainted(csp); + return; } /* @@ -2588,13 +2614,16 @@ static void chat(struct client_state *csp) if (len <= 0) { + /* XXX: not sure if this is necessary. */ + mark_server_socket_tainted(csp); break; /* "game over, man" */ } if (write_socket(csp->sfd, buf, (size_t)len)) { log_error(LOG_LEVEL_ERROR, "write to: %s failed: %E", http->host); - break; + mark_server_socket_tainted(csp); + return; } continue; } @@ -2635,7 +2664,8 @@ static void chat(struct client_state *csp) */ log_error(LOG_LEVEL_ERROR, "Already forwarded the original headers. " "Unable to tell the client about the problem."); - break; + mark_server_socket_tainted(csp); + return; } rsp = error_response(csp, "connect-failed", errno); @@ -2730,7 +2760,8 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_ERROR, "write modified content to client failed: %E"); freez(hdr); freez(p); - break; + mark_server_socket_tainted(csp); + return; } freez(hdr); @@ -2787,7 +2818,8 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_ERROR, "Out of memory while trying to flush."); rsp = cgi_error_memory(); send_crunch_response(csp, rsp); - break; + mark_server_socket_tainted(csp); + return; } hdrlen = strlen(hdr); @@ -2798,7 +2830,8 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_CONNECT, "Flush header and buffers to client failed: %E"); freez(hdr); - break; + mark_server_socket_tainted(csp); + return; } /* @@ -2817,7 +2850,8 @@ static void chat(struct client_state *csp) if (write_socket(csp->cfd, buf, (size_t)len)) { log_error(LOG_LEVEL_ERROR, "write to client failed: %E"); - break; + mark_server_socket_tainted(csp); + return; } } byte_count += (size_t)len; @@ -2836,7 +2870,8 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_ERROR, "Out of memory while looking for end of server headers."); rsp = cgi_error_memory(); send_crunch_response(csp, rsp); - break; + mark_server_socket_tainted(csp); + return; } header_start = csp->iob->cur; @@ -2872,7 +2907,8 @@ static void chat(struct client_state *csp) log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 502 0", csp->ip_addr_str, http->cmd); write_socket(csp->cfd, NO_SERVER_DATA_RESPONSE, strlen(NO_SERVER_DATA_RESPONSE)); free_http_request(http); - break; + mark_server_socket_tainted(csp); + return; } assert(csp->headers->first->str); @@ -2896,7 +2932,8 @@ static void chat(struct client_state *csp) write_socket(csp->cfd, INVALID_SERVER_HEADERS_RESPONSE, strlen(INVALID_SERVER_HEADERS_RESPONSE)); free_http_request(http); - break; + mark_server_socket_tainted(csp); + return; } /* @@ -2923,7 +2960,8 @@ static void chat(struct client_state *csp) * and are done here after cleaning up. */ freez(hdr); - break; + mark_server_socket_tainted(csp); + return; } /* Buffer and pcrs filter this if appropriate. */ @@ -2952,7 +2990,8 @@ static void chat(struct client_state *csp) * to the client... it probably can't hear us anyway. */ freez(hdr); - break; + mark_server_socket_tainted(csp); + return; } byte_count += (size_t)len; @@ -2987,17 +3026,8 @@ static void chat(struct client_state *csp) } continue; } - /* - * If we reach this point, the server socket is tainted - * (most likely because we didn't read everything the - * server sent us) and reusing it would lead to garbage. - */ - if ((csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE)) - { - log_error(LOG_LEVEL_CONNECT, "Unsetting keep-alive flag."); - csp->flags &= ~CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE; - } - return; + mark_server_socket_tainted(csp); + return; /* huh? we should never get here */ } if (csp->content_length == 0)