@matheusbsbs / matheus-bagliano / commits / 3c59c50d76
Fork 0

builtin-branch: use strbuf in delete_branches()

In case the length of branch name is greather then PATH_MAX-7, we write to unallocated memory otherwise. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Miklos Vajna committed Nov 17, 2008 at 21:48 UTC 3c59c50d76cd479caf14cab73fdb09b68597d5e5
1 file changed +4 -4
builtin-branch.c
+4 -4
@@ -97,7 +97,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
97 unsigned char sha1[20];
98 char *name = NULL;
99 const char *fmt, *remote;
100 - char section[PATH_MAX];
100 int i;
101 int ret = 0;
102
@@ -165,11 +164,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
164 argv[i]);
165 ret = 1;
166 } else {
167 + struct strbuf buf = STRBUF_INIT;
168 printf("Deleted %sbranch %s.\n", remote, argv[i]);
169 - snprintf(section, sizeof(section), "branch.%s",
170 - argv[i]);
171 - if (git_config_rename_section(section, NULL) < 0)
169 + strbuf_addf(&buf, "branch.%s", argv[i]);
170 + if (git_config_rename_section(buf.buf, NULL) < 0)
171 warning("Update of config-file failed");
172 + strbuf_release(&buf);
173 }
174 }
175