git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] http-backend: Fix access beyond end of string.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 16, 2009, 01:36 UTC
Message-ID
<20091116013654.GX11919@spearce.org>
In-Reply-To
<1258233058-2348-1-git-send-email-tarmigan+git@gmail.com>
Tarmigan Casebolt <tarmigan+git@gmail.com> wrote:
Show 12 quoted lines
> diff --git a/http-backend.c b/http-backend.c
> index f8ea9d7..ab9433d 100644
> --- a/http-backend.c
> +++ b/http-backend.c
> @@ -634,7 +634,7 @@ int main(int argc, char **argv)
>  			cmd = c;
>  			cmd_arg = xmalloc(n);
>  			strncpy(cmd_arg, dir + out[0].rm_so + 1, n);
> -			cmd_arg[n] = '\0';
> +			cmd_arg[n-1] = '\0';
>  			dir[out[0].rm_so] = 0;
>  			break;
Shouldn't this instead be:
diff --git a/http-backend.c b/http-backend.c
index 9021266..16ec635 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -626,7 +626,7 @@ int main(int argc, char **argv)
 			}
 
 			cmd = c;
-			cmd_arg = xmalloc(n);
+			cmd_arg = xmalloc(n + 1);
 			strncpy(cmd_arg, dir + out[0].rm_so + 1, n);
 			cmd_arg[n] = '\0';
 			dir[out[0].rm_so] = 0;

The cmd_arg string was simply allocated too small.  Your fix is
terminating the string one character too short which would cause
get_loose_object and get_pack_file to break.
-- 
Shawn.
Previous: Shawn O. PearceNext: Jeff King
Message 4 of 8 in “http-backend: Fix access beyond end of string.”
  1. 1/2 http-backend: Fix access beyond end of string.Tarmigan Casebolt, Nov 14, 2009
  2. 2/2 http-backend: Let gcc check the format of more printf-type functions.Tarmigan Casebolt, Nov 14, 2009
  3. Shawn O. PearceNov 16, 2009
  4. Shawn O. PearceNov 16, 2009
  5. Jeff KingNov 16, 2009
  6. Junio C HamanoNov 16, 2009
  7. TarmiganNov 17, 2009
  8. Brian GernhardtNov 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.