Skip to content

Commit

Permalink
http-backend: Fix access beyond end of string.
Browse files Browse the repository at this point in the history
Found with valgrind while looking for Content-Length corruption in
smart http.

Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Tarmigan Casebolt authored and Junio C Hamano committed Nov 16, 2009
1 parent 4a5328d commit 48aec1b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions http-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ int main(int argc, char **argv)
if (regcomp(&re, c->pattern, REG_EXTENDED))
die("Bogus regex in service table: %s", c->pattern);
if (!regexec(&re, dir, 1, out, 0)) {
size_t n = out[0].rm_eo - out[0].rm_so;
size_t n;

if (strcmp(method, c->method)) {
const char *proto = getenv("SERVER_PROTOCOL");
Expand All @@ -629,9 +629,10 @@ int main(int argc, char **argv)
}

cmd = c;
n = out[0].rm_eo - out[0].rm_so;
cmd_arg = xmalloc(n);
strncpy(cmd_arg, dir + out[0].rm_so + 1, n);
cmd_arg[n] = '\0';
memcpy(cmd_arg, dir + out[0].rm_so + 1, n-1);
cmd_arg[n-1] = '\0';
dir[out[0].rm_so] = 0;
break;
}
Expand Down

0 comments on commit 48aec1b

Please sign in to comment.