Thread (4 messages) flat view 4 messages, 2 authors, 2016-06-15

Re: [RFD PATCH] git-fetch--tool and "insanely" long actions

From: A Large Angry SCM <hidden>
Date: 2016-06-15 22:43:06

Julian Phillips wrote:
quoted hunk ↗ jump to hunk
On Thu, 19 Apr 2007, A Large Angry SCM wrote:
quoted
This fixes a problem my repository mirroring script has been having since
the git-fetch--tool was added to master in the middle of March. However,
it is not a proper fix since it causes actual errors from snprintf() to be
ignored. A proper fix is complicated by the lack of a consistent indicator
that the buffer is too small across snprintf() implementations.
.
.
.
quoted
      if (sizeof(msg) <= len)
-             die("insanely long action");
+             msg[sizeof(msg)-1] = '\0';
Or you could just let the whole thing through?
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index e9d6764..9b5ae9f 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -36,21 +36,26 @@ static int update_ref(const char *action,
 		      unsigned char *oldval)
 {
 	int len;
-	char msg[1024];
+	char buffer[1024];
+	int ret = 0;
+	char *msg = buffer;
 	char *rla = getenv("GIT_REFLOG_ACTION");
 	static struct ref_lock *lock;
 
 	if (!rla)
 		rla = "(reflog update)";
-	len = snprintf(msg, sizeof(msg), "%s: %s", rla, action);
-	if (sizeof(msg) <= len)
-		die("insanely long action");
+	len = strlen(rla) + strlen(action) + 3;
+	if (len > sizeof(buffer))
+		msg = xmalloc(len);
+	snprintf(msg, len, "%s: %s", rla, action);
 	lock = lock_any_ref_for_update(refname, oldval);
 	if (!lock)
-		return 1;
+		ret = 1;
 	if (write_ref_sha1(lock, sha1, msg) < 0)
-		return 1;
-	return 0;
+		ret = 1;
+	if (msg != buffer)
+		free(msg);
+	return ret;
 }
 
 static int update_local_ref(const char *name,

See the last sentence in my original message. Yours also ignores errors 
from snprintf().
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help