Possible problem with parse_uri if the URL is malformed

If the URL that is passed to parse_uri just contains a hostname withouy any path (e.g. http://www.foo.bar) then the function might cause a core dump because there is a small bug in the parse_uri function…

The diff for the parse_uri function looks as follows:

/* Extract the host name */
hostbegin = uri + 7;
- hostend = strpbrk(hostbegin, ” :/\r\n\0″);
+ /* does not work because it maps to the end-of-string and strpbrk
+ * will return NULL
+ */
+ //hostend = strpbrk(hostbegin, ” :/\r\n\0″);
+ hostend = strpbrk(hostbegin, ” :/\r\n”);
+ if (hostend == NULL) hostend = hostbegin+strlen(hostbegin);
len = hostend – hostbegin;
strncpy(hostname, hostbegin, len);
hostname[len] = ‘\0′;

Of course you can download the corrected handout at http://www.lst.inf.ethz.ch/teaching/lectures/ss07/2100/proxy_lab/proxylab-handout.tar

0 Responses to “Possible problem with parse_uri if the URL is malformed”


  • No Comments

Leave a Reply