Skip to contentSkip to conversation

fix use of sometimes uninitialized variable 'msg'

PATCH In review Michael Coleman 3 participants 11 messages Jun 15, 2016

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 fix uninitialized use of msg buffer

---
 builtin-branch.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
builtin-branch.c +1 -1
index d60690b..ac64b99 100644
@@ -315,7 +315,7 @@ static void create_branch(const char *name, const char *start_name,
 	struct ref_lock *lock;
 	struct commit *commit;
 	unsigned char sha1[20];
-	char ref[PATH_MAX], msg[PATH_MAX + 20];
+	char ref[PATH_MAX], msg[PATH_MAX + 20] = { 0 };
 
 	snprintf(ref, sizeof ref, "refs/heads/%s", name);
 	if (check_ref_format(ref))
Signature · 1 line
1.5.0.rc3
#2 lore raw

PATCH 1/1 builtin-branch: be prepared for ref-logging

The test for reflog parameter to create_branch() should also have tested for log_all_ref_updates. But there is no good reason not to prepare a reflog message, so lets just do it.

---

If log_all_ref_updates==1 then the reflog will get an empty message with your patch. That is better than using an uninitialized message, but I think it's still better to just prepare a proper message.

 builtin-branch.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
builtin-branch.c +1 -6
index d60690b..16b589e 100644
@@ -342,12 +342,7 @@ static void create_branch(const char *name, const char *start_name,
 	if (!lock)
 		die("Failed to lock ref for update: %s.", strerror(errno));
 
-	if (reflog) {
-		log_all_ref_updates = 1;
-		snprintf(msg, sizeof msg, "branch: Created from %s",
-			 start_name);
-	}
-
+	snprintf(msg, sizeof msg, "branch: Created from %s", start_name);
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		die("Failed to write ref: %s.", strerror(errno));
 }
Signature · 1 line
1.5.0.rc2.ge4b0e
#3 lore raw

Re: [PATCH] builtin-branch: be prepared for ref-logging

Quoted 10 lines · Lars Hjemli

The test for reflog parameter to create_branch() should also have tested for log_all_ref_updates. But there is no good reason not to prepare a reflog message, so lets just do it.

---

If log_all_ref_updates==1 then the reflog will get an empty message with your patch. That is better than using an uninitialized message, but I think it's still better to just prepare a proper message.

True, but don't you still need to set log_all_ref_updates while you call write_ref_sha1() for that ref in order to make sure that log_ref_write() sets O_CREAT in oflags?

#4 lore raw

PATCH 1/1 builtin-branch: be prepared for ref-logging

In reply to Michael Coleman

The test for reflog parameter to create_branch() should also have tested for log_all_ref_updates. But there is no good reason not to prepare a reflog message, so lets just do it.

---

Sorry, the previous patch was obviously no good, since it didn't honour the case where (reflog==1 && log_all_ref_updates==0)

This one should be better.

 builtin-branch.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
builtin-branch.c +2 -4
index d60690b..a8c8c98 100644
@@ -342,12 +342,10 @@ static void create_branch(const char *name, const char *start_name,
 	if (!lock)
 		die("Failed to lock ref for update: %s.", strerror(errno));
 
-	if (reflog) {
+	if (reflog)
 		log_all_ref_updates = 1;
-		snprintf(msg, sizeof msg, "branch: Created from %s",
-			 start_name);
-	}
 
+	snprintf(msg, sizeof msg, "branch: Created from %s", start_name);
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		die("Failed to write ref: %s.", strerror(errno));
 }
Signature · 1 line
1.5.0.rc2.ge4b0e
#5 lore raw

Re: [PATCH] builtin-branch: be prepared for ref-logging

Quoted 9 lines · Lars Hjemli

The test for reflog parameter to create_branch() should also have tested for log_all_ref_updates. But there is no good reason not to prepare a reflog message, so lets just do it.

---

Sorry, the previous patch was obviously no good, since it didn't honour the case where (reflog==1 && log_all_ref_updates==0)

Ah, I did not see your fix-up patch before I sent out my comments.

Funny thing is that I thought I fixed this already, but apparently I didn't. It could have been one of my "fixing in working tree, sending out a patch to the list for comments and then forgetting to apply it". Maybe not.

In any case, thanks for the fix.

#7 lore raw

Re: [PATCH] builtin-branch: be prepared for ref-logging

Quoted 8 lines · Lars Hjemli
Quoted 1 line · Junio C Hamano

Funny thing is that I thought I fixed this already

Infact, you did:

http://article.gmane.org/gmane.comp.version-control.git/37197

Don't know what happend to this one...

It turns out that I was missing another patch from the same day.

	http://article.gmane.org/gmane.comp.version-control.git/37238

I guess we need a patch secretary whose job is to keep track of all the patches sent to the list and make sure nothing stays in limbo X-<.

#9 lore raw

Re: [PATCH] builtin-branch: be prepared for ref-logging

Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Lars Hjemli
Quoted 1 line · Junio C Hamano

Funny thing is that I thought I fixed this already

Quoted 7 lines
Quoted 5 lines

Infact, you did:

http://article.gmane.org/gmane.comp.version-control.git/37197

Don't know what happend to this one...

Thanks, and I do think that patch is better ;-).

Agreed

Signature · 1 line
larsh
#10 lore raw
In reply to Michael Coleman
Quoted 3 lines · Michael Coleman <tutufan <at> gmail.com> writes:

Oops--I didn't realize a header email was going to be sent out, too. Not quite sure what happened there. When I tested it before, I thought only one email got sent.

Mike