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

[PATCH] Fix potentially dangerous uses of mkpath and git_path

From
Alex Riesen <raa.lkml@gmail.com>
Date
Oct 26, 2008, 22:08 UTC
Message-ID
<20081026220852.GC18594@blimp.localdomain>
In-Reply-To
<20081026215913.GA18594@blimp.localdomain>

Replace them with mksnpath/git_snpath and a local buffer for the resulting string.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 builtin-apply.c        |    4 ++--
 builtin-for-each-ref.c |    6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index cfd8fce..4c4d1e1 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2841,8 +2841,8 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned
 		unsigned int nr = getpid();
 
 		for (;;) {
-			const char *newpath;
-			newpath = mkpath("%s~%u", path, nr);
+			char newpath[PATH_MAX];
+			mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
 			if (!try_create_file(newpath, mode, buf, size)) {
 				if (!rename(newpath, path))
 					return;
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index fa6c1ed..e46b7ad 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -620,14 +620,16 @@ static char *get_short_ref(struct refinfo *ref)
 		for (j = 0; j < i; j++) {
 			const char *rule = ref_rev_parse_rules[j];
 			unsigned char short_objectname[20];
+			char refname[PATH_MAX];
 
 			/*
 			 * the short name is ambiguous, if it resolves
 			 * (with this previous rule) to a valid ref
 			 * read_ref() returns 0 on success
 			 */
-			if (!read_ref(mkpath(rule, short_name_len, short_name),
-				      short_objectname))
+			mksnpath(refname, sizeof(refname),
+				 rule, short_name_len, short_name);
+			if (!read_ref(refname, short_objectname))
 				break;
 		}
 
-- 
1.6.0.3.540.g3f8b
Previous: Alex RiesenNext: Johannes Sixt
Message 3 of 10 in “Add mksnpath and git_snpath which allow to specify the output buffer”
  1. Add mksnpath and git_snpath which allow to specify the output bufferAlex Riesen, Oct 26, 2008
  2. Fix mkpath abuse in dwim_ref and dwim_log of sha1_name.cAlex Riesen, Oct 26, 2008
  3. Fix potentially dangerous uses of mkpath and git_pathAlex Riesen, Oct 26, 2008
  4. Johannes SixtOct 27, 2008
  5. Alex RiesenOct 27, 2008
  6. Junio C HamanoOct 27, 2008
  7. Alex RiesenOct 27, 2008
  8. Junio C HamanoOct 28, 2008
  9. Alex RiesenOct 28, 2008
  10. Alex RiesenOct 28, 2008

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.