HTCookie.c Patch
Jesse Morgan <[email protected]> Wed, 14 Jun 2006 10:10:41 -0700
| Newsgroups | gmane.comp.lib.libwww |
|---|---|
| Message-ID | <[email protected]> |
--qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hey Guys, I was using libwww and discovered issues when the value of a cookie is either null or contains = signs. The attached patch fixes the issue. The patch is against the 5.4.0 release. -- Jesse Morgan 253-397-1372 [email protected] www.jesterpm.net --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="w3c-libwww-5.4.0.patch" diff -rup w3c-libwww-5.4.0/Library/src/HTCookie.c w3c-libwww-5.4.0.patched/Library/src/HTCookie.c --- w3c-libwww-5.4.0/Library/src/HTCookie.c 1999-07-30 18:30:16.000000000 -0700 +++ w3c-libwww-5.4.0.patched/Library/src/HTCookie.c 2006-06-14 09:51:48.000000000 -0700 @@ -242,17 +242,47 @@ PRIVATE BOOL HTCookieHolder_deleteAll (v /* ------------------------------------------------------------------------- */ /* +** Added By Jesse Morgan <[email protected]> on 2006-05-22 +** Splits a KEY=VALUE pair into a KEY and VALUE +*/ +PRIVATE int HTCookie_splitPair (char * pair, char ** key, char ** value) +{ + char * index = strchr(pair, '='); + + if (index == NULL) { + return HT_ERROR; + } + + *key = pair; + *index = '\0'; + *value = ++index; + + return HT_OK; +} + + +/* ** MIME header parser for the Set-Cookie header field. We parse the cookies ** and create HTCookie objects and store them in the cookie holder so that ** the cookie after filter can deal with them accordingly. +** Modified by Jesse Morgan <[email protected]> on 2006-05-22 to properly +** parse cookies such as: Set-Cookie: MYUSERINFO=; and +** MSCulture=IP=000.000.000.000 */ PRIVATE int HTCookie_parseSetCookie (HTRequest * request, HTResponse * response, char * token, char * value) { - char * cookie_name = HTNextField(&value); - char * cookie_value = HTNextField(&value); - if (cookie_name && *cookie_name && cookie_value) { + + + char * cookie_name = NULL; + char * cookie_value = NULL; + + if (HTCookie_splitPair(HTNextParam(&value), &cookie_name, &cookie_value) != HT_OK) { + return HT_ERROR; /* Malformed Cookie */ + } + + if (cookie_name && *cookie_name && cookie_value) { HTCookie * cookie = HTCookie_new(); char * param_pair; @@ -264,8 +294,13 @@ PRIVATE int HTCookie_parseSetCookie (HTR /* Parse cookie parameters */ while ((param_pair = HTNextParam(&value))) { - char * tok = HTNextField(¶m_pair); - char * val = param_pair; + char * tok = NULL; + char * val = NULL; + + if (HTCookie_splitPair(param_pair, &tok, &val) != HT_OK) { + return HT_ERROR; /* Malformed Cookie */ + } + if (tok) { if (!strcasecomp(tok, "expires") && val && *val) { HTTRACE(STREAM_TRACE, "Cookie...... Expires `%s\'\n" _ val); @@ -288,6 +323,7 @@ PRIVATE int HTCookie_parseSetCookie (HTR return HT_OK; } + /* ** Check whether the application provides us with a cookie or more. */ --qMm9M+Fa2AknHoGS--