aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-02-26 13:07:53 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-02-26 13:07:53 +0000
commita23a897ad219e15b9bfd1f8a740465f3c0f98bfc (patch)
treec9f7b14d27f29d0cef074b0370f2fee62d337cfc /lib
parentd9c244278d142ec836fddd522fbe6417810d21b3 (diff)
removed crash on weird input, this also better discards silly input
Diffstat (limited to 'lib')
-rw-r--r--lib/cookie.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/lib/cookie.c b/lib/cookie.c
index 8ba09832f..4362bd257 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2002, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* In order to be useful for every potential user, curl and libcurl are
* dual-licensed under the MPL and the MIT/X-derivate licenses.
@@ -127,15 +127,21 @@ Curl_cookie_add(struct CookieInfo *c,
if(httpheader) {
/* This line was read off a HTTP-header */
-
+ char *sep;
semiptr=strchr(lineptr, ';'); /* first, find a semicolon */
ptr = lineptr;
do {
/* we have a <what>=<this> pair or a 'secure' word here */
- if(strchr(ptr, '=')) {
+ sep = strchr(ptr, '=');
+ if(sep && (!semiptr || (semiptr>sep)) ) {
+ /*
+ * There is a = sign and if there was a semicolon too, which make sure
+ * that the semicolon comes _after_ the equal sign.
+ */
+
name[0]=what[0]=0; /* init the buffers */
- if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
- MAX_COOKIE_LINE_TXT "[^;\r\n]",
+ if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;=]=%"
+ MAX_COOKIE_LINE_TXT "[^;\r\n ]",
name, what)) {
/* this is a legal <what>=<this> pair */
if(strequal("path", name)) {
@@ -187,8 +193,11 @@ Curl_cookie_add(struct CookieInfo *c,
}
}
- if(!semiptr)
- continue; /* we already know there are no more cookies */
+ if(!semiptr || !*semiptr) {
+ /* we already know there are no more cookies */
+ semiptr = NULL;
+ continue;
+ }
ptr=semiptr+1;
while(ptr && *ptr && isspace((int)*ptr))
@@ -198,9 +207,23 @@ Curl_cookie_add(struct CookieInfo *c,
if(!semiptr && *ptr)
/* There are no more semicolons, but there's a final name=value pair
coming up */
- semiptr=ptr;
+ semiptr=strchr(ptr, '\0');
} while(semiptr);
+ if(NULL == co->name) {
+ /* we didn't get a cookie name, this is an illegal line, bail out */
+ if(co->domain)
+ free(co->domain);
+ if(co->path)
+ free(co->path);
+ if(co->name)
+ free(co->name);
+ if(co->value)
+ free(co->value);
+ free(co);
+ return NULL;
+ }
+
if(NULL == co->domain)
/* no domain given in the header line, set the default now */
co->domain=domain?strdup(domain):NULL;