Skip to content

Commit 3c59c50

Browse files
Miklos Vajnagitster
authored andcommitted
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>
1 parent 4757745 commit 3c59c50

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

builtin-branch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
9797
unsigned char sha1[20];
9898
char *name = NULL;
9999
const char *fmt, *remote;
100-
char section[PATH_MAX];
101100
int i;
102101
int ret = 0;
103102

@@ -165,11 +164,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
165164
argv[i]);
166165
ret = 1;
167166
} else {
167+
struct strbuf buf = STRBUF_INIT;
168168
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)
172171
warning("Update of config-file failed");
172+
strbuf_release(&buf);
173173
}
174174
}
175175

0 commit comments

Comments
 (0)