X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=parsers.c;h=c2020c75f25398420f2b9d41594210dcb3609403;hb=cd2137e61f4ad5341297c8716f8e7c07fb62441c;hp=2567465bab0b631ea6ee9f53290aee39824c2bab;hpb=de4a6ca39d58cf66faddb671c90094ec1f17fe61;p=privoxy.git diff --git a/parsers.c b/parsers.c index 2567465b..c2020c75 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.206 2009/08/19 15:57:13 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.209 2009/09/06 14:11:06 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -1754,15 +1754,45 @@ static jb_err client_keep_alive(struct client_state *csp, char **header) } +/********************************************************************* + * + * Function : get_content_length + * + * Description : Gets the content length specified in a + * Content-Length header. + * + * Parameters : + * 1 : header = The Content-Length header. + * 2 : length = Storage to return the value. + * + * Returns : JB_ERR_OK on success, or + * JB_ERR_PARSE if no value is recognized. + * + *********************************************************************/ +static jb_err get_content_length(const char *header, unsigned long long *length) +{ + assert(header[14] == ':'); + +#ifdef _WIN32 + assert(sizeof(unsigned long long) > 4); + if (1 != sscanf(header+14, ": %I64u", length)) +#else + if (1 != sscanf(header+14, ": %llu", length)) +#endif + { + return JB_ERR_PARSE; + } + + return JB_ERR_OK; +} + + /********************************************************************* * * Function : client_save_content_length * * Description : Save the Content-Length sent by the client. * - * XXX: Shares code with the server version - * that should be factored out. - * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) * 2 : header = On input, pointer to header to modify. @@ -1780,11 +1810,7 @@ static jb_err client_save_content_length(struct client_state *csp, char **header assert(*(*header+14) == ':'); -#ifdef _WIN32 - if (1 != sscanf(*header+14, ": %I64u", &content_length)) -#else - if (1 != sscanf(*header+14, ": %llu", &content_length)) -#endif + if (JB_ERR_OK != get_content_length(*header, &content_length)) { log_error(LOG_LEVEL_ERROR, "Crunching invalid header: %s", *header); freez(*header); @@ -2263,11 +2289,7 @@ static jb_err server_save_content_length(struct client_state *csp, char **header assert(*(*header+14) == ':'); -#ifdef _WIN32 - if (1 != sscanf(*header+14, ": %I64u", &content_length)) -#else - if (1 != sscanf(*header+14, ": %llu", &content_length)) -#endif + if (JB_ERR_OK != get_content_length(*header, &content_length)) { log_error(LOG_LEVEL_ERROR, "Crunching invalid header: %s", *header); freez(*header); @@ -3789,6 +3811,17 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) { char *expiration_date = cur_tag + 8; /* Skip "[Ee]xpires=" */ + if ((expiration_date[0] == '"') + && (expiration_date[1] != '\0')) + { + /* + * Skip quotation mark. RFC 2109 10.1.2 seems to hint + * that the expiration date isn't supposed to be quoted, + * but some servers do it anyway. + */ + expiration_date++; + } + /* Did we detect the date properly? */ if (JB_ERR_OK != parse_header_time(expiration_date, &cookie_time)) {