path: root/sha1_name.c
diff options
authorJunio C Hamano <>2008-10-27 05:24:44 (GMT)
committerJunio C Hamano <>2008-10-27 05:24:44 (GMT)
commit356af64d84076baaf90b0bf8adb7245771264e5a (patch)
tree008ecc6fdb6323d2bac3e09be6dce5b0de5f64cb /sha1_name.c
parent304d058370a9a797c38ec739c6d39fa45d9ed8e5 (diff)
parent9fa03c177ff826b439537072338af958fe01c257 (diff)
Merge branch 'ar/maint-mksnpath' into HEAD
* ar/maint-mksnpath: Fix potentially dangerous uses of mkpath and git_path Fix mkpath abuse in dwim_ref and dwim_log of sha1_name.c Add mksnpath which allows you to specify the output buffer
Diffstat (limited to 'sha1_name.c')
1 files changed, 4 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 41b6809..159c2ab8 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -245,11 +245,13 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
*ref = NULL;
for (p = ref_rev_parse_rules; *p; p++) {
+ char fullref[PATH_MAX];
unsigned char sha1_from_ref[20];
unsigned char *this_result;
this_result = refs_found ? sha1_from_ref : sha1;
- r = resolve_ref(mkpath(*p, len, str), this_result, 1, NULL);
+ mksnpath(fullref, sizeof(fullref), *p, len, str);
+ r = resolve_ref(fullref, this_result, 1, NULL);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);
@@ -272,7 +274,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
char path[PATH_MAX];
const char *ref, *it;
- strcpy(path, mkpath(*p, len, str));
+ mksnpath(path, sizeof(path), *p, len, str);
ref = resolve_ref(path, hash, 1, NULL);
if (!ref)