Don't unescape %00
Hrvoje Niksic <[email protected]> Thu, 05 May 2005 15:57:40 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
This patch prevents %00 from being unescaped inside Wget because
unescaping it effectively truncates the resulting C string. This is
not a grave bug, but it results in counter-intuitive behavior, such
as:
$ wget http://host/foo%00bar
--15:52:34-- http://host/foo%00bar
=> `foo'
...
$ wget http://host/%00
--15:52:51-- http://host/%00
=> `index.html'
Rather than truncating the string I think it's more better to just
leave %00 as-is. With the below patch the above result in:
$ wget http://host/foo%00bar
--15:54:21-- http://host/foo%00bar
=> `foo%00bar'
...
$ wget http://host/%00
--15:54:36-- http://host/%00
=> `%00'
2005-05-05 Hrvoje Niksic <[email protected]>
* url.c (url_unescape): Don't unescape %00, it effectively
truncates the string.
Index: src/url.c
===================================================================
RCS file: /pack/anoncvs/wget/src/url.c,v
retrieving revision 1.121
diff -u -r1.121 url.c
--- src/url.c 2005/05/03 15:24:30 1.121
+++ src/url.c 2005/05/05 13:56:18
@@ -175,10 +175,16 @@
}
else
{
+ char c;
/* Do nothing if '%' is not followed by two hex digits. */
if (!h[1] || !h[2] || !(ISXDIGIT (h[1]) && ISXDIGIT (h[2])))
goto copychar;
- *t = X2DIGITS_TO_NUM (h[1], h[2]);
+ c = X2DIGITS_TO_NUM (h[1], h[2]);
+ /* Don't unescape %00 because there is no way to insert it
+ into a C string without effectively truncating it. */
+ if (c == '\0')
+ goto copychar;
+ *t = c;
h += 2;
}
}