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

[patch] git: fix 1-byte overflow in show-files.c

From
IMIngo Molnar <mingo@elte.hu>
Date
Apr 14, 2005, 12:53 UTC
Message-ID
<20050414125354.GB15420@elte.hu>
In-Reply-To
<20050414121819.GA14380@elte.hu>

this patch fixes a 1-byte overflow in show-files.c (looks narrow is is probably not exploitable). A specially crafted db object (tree) might trigger this overflow.

'fullname' is an array of 4096+1 bytes, and we do readdir(), which produces entries that have strings with a length of 0-255 bytes. With a long enough 'base', it's possible to construct a tree with a name in it that has directory whose name ends precisely at offset 4095. At that point this code:

                        case DT_DIR:
                                memcpy(fullname + baselen + len, "/", 2);

will attempt to append a "/" string to the directory name - resulting in a 1-byte overflow (a zero byte is written to offset 4097, which is outside the array).

	Ingo
Signed-off-by: Ingo Molnar <mingo@elte.hu>

--- show-files.c.orig +++ show-files.c

@@ -49,7 +49,7 @@ static void read_directory(const char *p
 
 	if (dir) {
 		struct dirent *de;
-		char fullname[MAXPATHLEN + 1];
+		char fullname[MAXPATHLEN + 2]; // +1 byte for trailing slash
 		memcpy(fullname, base, baselen);
 
 		while ((de = readdir(dir)) != NULL) {
Previous: Ingo MolnarNext: Petr Baudis
Message 10 of 22 in “git: fix memory leak in checkout-cache.c”
  1. git: fix memory leak in checkout-cache.cIngo Molnar, Apr 14, 2005
  2. git: fix memory leak #2 in checkout-cache.cIngo Molnar, Apr 14, 2005
  3. git: cleanup in ls-tree.cIngo Molnar, Apr 14, 2005
  4. git: fix memory leaks in read-tree.cIngo Molnar, Apr 14, 2005
  5. git: fix rare memory leak in rev-tree.cIngo Molnar, Apr 14, 2005
  6. git: report parse_commit() errors in rev-tree.cIngo Molnar, Apr 14, 2005
  7. git: fix memory leak in show-diff.cIngo Molnar, Apr 14, 2005
  8. git: fix overflow in update-cache.cIngo Molnar, Apr 14, 2005
  9. cleanup: read_sha1_file() -> malloc_read_sha1_file()Ingo Molnar, Apr 14, 2005
  10. git: fix 1-byte overflow in show-files.cIngo Molnar, Apr 14, 2005
  11. Petr BaudisApr 17, 2005
  12. Ingo MolnarApr 18, 2005
  13. git: fix memory leaks in update-cache.cIngo Molnar, Apr 14, 2005
  14. git: clean up add_file_to_cache() in update-cache.cIngo Molnar, Apr 14, 2005
  15. git: fix memory leak #3 in update-cache.cIngo Molnar, Apr 14, 2005
  16. git: fix memory leaks in read-cache.cIngo Molnar, Apr 14, 2005
  17. git: fix memory leak #2 in read-cache.cIngo Molnar, Apr 14, 2005
  18. Ingo MolnarApr 14, 2005
  19. Martin SchlemmerApr 14, 2005
  20. Linus TorvaldsApr 14, 2005
  21. Ingo MolnarApr 14, 2005
  22. git: fix memory leak in write-tree.cIngo Molnar, Apr 14, 2005

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.