bug in cookies

"Guido Meyer" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi list!

I foud a bug in the cookie part of the gateway.

Scenario:

If you want to set a cookie as follows:
name = test_cookie with value = test
exoire-time = -1
path = NULL
domain = NULL

Then the wapbox crashes in the have_cookie function:
if(...
(value->path == NULL || ((value->path != NULL) &&
octstr_compare(value->path, cookie->path) == 0)) &&...

The two octstr in octstr_compare must not NULL, but some values of the
cookie could be NULL.
The included patch corrects this.


I have read in the php documentation that you can delete a cookie if you
only set the cookie-name. If you do this, the expire-time is -1 (which also
mean no expire-time). In Kannel the expire-timne is checked against 0, so
you can't delete a cookie that way. In the included patch this is corrected.

For me it works fine, I hope i have not too special scenarios so that it
won't work as expected.

Regards
Guido


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Mentana GmbH
Dipl.-Inform. Guido Meyer
Softwareentwicklung

Lerchenkamp 11
D-31137 Hildesheim
Germany

Tel.     ++49-5121-20627-64
(Zentrale ++49-5121-20627-0)
Fax      ++49-5121-20627-99

mailto:[email protected]
http://www.mentana.de
cookies.diff (application/octet-stream, 2.5 KB)
--- cookies.c	Fri Nov 22 11:57:03 2002
+++ cookies.c.org	Fri Nov 22 11:57:40 2002
@@ -313,32 +313,36 @@
 		/* octstr_compare() now only returns 0 on an exact match or if both args are 0 */

 		debug ("wap.wsp.http", 0, "have_cookie: Comparing name (%s:%s), path (%s:%s), domain (%s:%s)",
-			   cookie->name == NULL ? "NULL" : octstr_get_cstr(cookie -> name),
+			   cookie->name == NULL ? "NULL" : octstr_get_cstr(cookie -> name),
 			   value->name == NULL ? "NULL" : octstr_get_cstr(value -> name),
-			   cookie->path == NULL ? "NULL" : octstr_get_cstr(cookie -> path),
+			   cookie->path == NULL ? "NULL" : octstr_get_cstr(cookie -> path),
 			   value->path == NULL ? "NULL" : octstr_get_cstr(value -> path),
-			   cookie->domain == NULL ? "NULL" : octstr_get_cstr(cookie -> domain),
+			   cookie->domain == NULL ? "NULL" : octstr_get_cstr(cookie -> domain),
 			   value->domain == NULL ? "NULL" : octstr_get_cstr(value -> domain));

 		/* Match on no value or value and value equality for name, path and domain */

-		if ( ( (value->name   == NULL || cookie->name   == NULL) || ( (value->name   != NULL) && octstr_compare(value->name, cookie->name)     == 0 ) ) &&
-		     ( (value->path   == NULL || cookie->path   == NULL) || ( (value->path   != NULL) && octstr_compare(value->path, cookie->path)     == 0 ) ) &&
-		     ( (value->domain == NULL || cookie->domain == NULL) || ( (value->domain != NULL) && octstr_compare(value->domain, cookie->domain) == 0 ) )
-		   ) {
+		if ((value->name == NULL ||
+			((value->name != NULL) && octstr_compare(value->name, cookie->name) == 0)) &&
+			(value->path == NULL ||
+			((value->path != NULL) && octstr_compare(value->path, cookie->path) == 0)) &&
+			((value->domain == NULL) ||
+			((value->domain != NULL) && octstr_compare(value->domain, cookie->domain) == 0))) {
+
 			/* We have a match according to 4.3.3 - discard the old one */

 			cookie_destroy(value);
 			list_delete(cookies, pos, 1);

 			/* Discard the new cookie also if max-age is 0 - set if expiry date is up */
-			if ( ( (cookie->name != NULL) && (cookie->path == NULL) && (cookie->domain == NULL) && (cookie->max_age <= 0) ) || (cookie->max_age == 0) ) {
+
+			if (cookie->max_age == 0) {
 				debug("wap.wsp.http", 0, "have_cookie: Discarding expired cookie (%s)",
 				      octstr_get_cstr(cookie->name));
 				return 1;
 			}

-			debug("wap.wsp.http", 0, "have_cookie: Updating cached cookie (%s)",
+			debug("wap.wsp.http", 0, "have_cookie: Updating cached cookie (%s)",
                   octstr_get_cstr (cookie->name));
 			break;
 		} else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.