Another quick fix for the dispatch callback, for when it goes through available 
callbacks looking for a match.  The problem is that if the request URI has an 
argument, the comparison is done on the bytes before the url parameter 
separator.  The result is that the lookup will result in mismatches, especially 
for a request URI like '/?some_arg=some_val' that will match the first callback 
found.

Two potential fixes are attached, one that modifies the string to replace the 
argument separator with a null char before the strcmp, and another that checks 
for a null char in the potential match (at the same offset as the argument 
separator.)

Thanks,

Elliot
--- libevent-1.3c-orig/http.c	2007-07-30 20:41:03.000000000 -0700
+++ libevent-1.3c/http.c	2007-08-01 12:46:26.000000000 -0700
@@ -1813,11 +1813,15 @@
 	char *p = strchr(req->uri, '?');
 	TAILQ_FOREACH(cb, callbacks, next) {
 		int res;
-		if (p == NULL)
+		if (p == NULL) {
 			res = strcmp(cb->what, req->uri) == 0;
-		else
-			res = strncmp(cb->what, req->uri,
-			    (size_t)(p - req->uri)) == 0;
+		}
+		else {
+			*p = '\0';
+			res = strcmp(cb->what, req->uri) == 0;
+			*p = '?';
+		}
+
 		if (res)
 			return (cb);
 	}
--- libevent-1.3c-orig/http.c	2007-07-30 20:41:03.000000000 -0700
+++ libevent-1.3c/http.c	2007-08-01 13:27:37.000000000 -0700
@@ -1808,16 +1808,23 @@
 evhttp_dispatch_callback(struct httpcbq *callbacks, struct evhttp_request *req)
 {
 	struct evhttp_cb *cb;
+	size_t offset = 0;
 
 	/* Test for different URLs */
 	char *p = strchr(req->uri, '?');
+	if (p != NULL)
+		offset = (size_t)(p - req->uri);
+
 	TAILQ_FOREACH(cb, callbacks, next) {
-		int res;
-		if (p == NULL)
+		int res = 0;
+		if (p == NULL) {
 			res = strcmp(cb->what, req->uri) == 0;
-		else
-			res = strncmp(cb->what, req->uri,
-			    (size_t)(p - req->uri)) == 0;
+		}
+		else {
+			res = ((strncmp(cb->what, req->uri, offset) == 0) &&
+					(cb->what[offset] == '\0'));
+		}
+
 		if (res)
 			return (cb);
 	}
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to