summaryrefslogtreecommitdiffabout
authorJim Meyering <meyering@redhat.com>2011-02-28 11:18:57 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2011-03-05 12:38:34 (UTC)
commitfc384b16fb9787380746000d3cea2d53fccc548e (patch) (side-by-side diff)
treed0a77d911c111e49904ab2f5061af22417f2b698
parent6bf2658f04089179aa373e47bd1d0718e808a59b (diff)
downloadcgit-fc384b16fb9787380746000d3cea2d53fccc548e.zip
cgit-fc384b16fb9787380746000d3cea2d53fccc548e.tar.gz
cgit-fc384b16fb9787380746000d3cea2d53fccc548e.tar.bz2
do not infloop on a query ending in %XY, for invalid hex X or Y
When a query ends in say %gg, (or any invalid hex) e.g., http://git.gnome.org/browse/gdlmm/commit/?id=%gg convert_query_hexchar calls memmove(txt, txt+3, 0), and then returns txt-1, so the loop in http_parse_querystring never terminates. The solution is to make the memmove also copy the trailing NUL. * html.c (convert_query_hexchar): Fix off-by-one error. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--html.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/html.c b/html.c
index d86b2c1..5336596 100644
--- a/html.c
+++ b/html.c
@@ -228,49 +228,49 @@ int html_include(const char *filename)
int hextoint(char c)
{
if (c >= 'a' && c <= 'f')
return 10 + c - 'a';
else if (c >= 'A' && c <= 'F')
return 10 + c - 'A';
else if (c >= '0' && c <= '9')
return c - '0';
else
return -1;
}
char *convert_query_hexchar(char *txt)
{
int d1, d2, n;
n = strlen(txt);
if (n < 3) {
*txt = '\0';
return txt-1;
}
d1 = hextoint(*(txt+1));
d2 = hextoint(*(txt+2));
if (d1<0 || d2<0) {
- memmove(txt, txt+3, n-3);
+ memmove(txt, txt+3, n-2);
return txt-1;
} else {
*txt = d1 * 16 + d2;
memmove(txt+1, txt+3, n-2);
return txt;
}
}
int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value))
{
char *t, *value = NULL, c;
if (!txt)
return 0;
t = txt = strdup(txt);
if (t == NULL) {
printf("Out of memory\n");
exit(1);
}
while((c=*t) != '\0') {
if (c=='=') {
*t = '\0';
value = t+1;