From: Junio C Hamano Date: Sat, 7 Oct 2017 07:27:54 +0000 (+0900) Subject: Merge branch 'tg/memfixes' X-Git-Tag: v2.15.0-rc1~21 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/98c03a0de83f5b5a98ac25d5639f647559c0e619?ds=inline;hp=-c Merge branch 'tg/memfixes' Fixes for a handful memory access issues identified by valgrind. * tg/memfixes: sub-process: use child_process.args instead of child_process.argv http-push: fix construction of hex value from path path.c: fix uninitialized memory access --- 98c03a0de83f5b5a98ac25d5639f647559c0e619 diff --combined http-push.c index d860c477c6,df969609be..493ee7d719 --- a/http-push.c +++ b/http-push.c @@@ -11,7 -11,6 +11,7 @@@ #include "list-objects.h" #include "sigchain.h" #include "argv-array.h" +#include "packfile.h" #ifdef EXPAT_NEEDS_XMLPARSE_H #include @@@ -1018,7 -1017,7 +1018,7 @@@ static int get_oid_hex_from_objpath(con memcpy(hex, path, 2); path += 2; path++; /* skip '/' */ - memcpy(hex, path, GIT_SHA1_HEXSZ - 2); + memcpy(hex + 2, path, GIT_SHA1_HEXSZ - 2); return get_oid_hex(hex, oid); } @@@ -1523,7 -1522,6 +1523,7 @@@ static int remote_exists(const char *pa break; case HTTP_ERROR: error("unable to access '%s': %s", url, curl_errorstr); + /* fallthrough */ default: ret = -1; } diff --combined path.c index 00ec04e7a5,2fecf854fe..2e09a7bce0 --- a/path.c +++ b/path.c @@@ -9,7 -9,6 +9,7 @@@ #include "worktree.h" #include "submodule-config.h" #include "path.h" +#include "packfile.h" static int get_st_mode_bits(const char *path, int *mode) { @@@ -34,11 -33,10 +34,10 @@@ static struct strbuf *get_pathname(void return sb; } - static char *cleanup_path(char *path) + static const char *cleanup_path(const char *path) { /* Clean it up */ - if (!memcmp(path, "./", 2)) { - path += 2; + if (skip_prefix(path, "./", &path)) { while (*path == '/') path++; } @@@ -47,7 -45,7 +46,7 @@@ static void strbuf_cleanup_path(struct strbuf *sb) { - char *path = cleanup_path(sb->buf); + const char *path = cleanup_path(sb->buf); if (path > sb->buf) strbuf_remove(sb, 0, path - sb->buf); } @@@ -64,7 -62,7 +63,7 @@@ char *mksnpath(char *buf, size_t n, con strlcpy(buf, bad_path, n); return buf; } - return cleanup_path(buf); + return (char *)cleanup_path(buf); } static int dir_prefix(const char *buf, const char *dir) @@@ -637,9 -635,8 +636,9 @@@ void strbuf_git_common_path(struct strb int validate_headref(const char *path) { struct stat st; - char *buf, buffer[256]; - unsigned char sha1[20]; + char buffer[256]; + const char *refname; + struct object_id oid; int fd; ssize_t len; @@@ -663,24 -660,24 +662,24 @@@ len = read_in_full(fd, buffer, sizeof(buffer)-1); close(fd); + if (len < 0) + return -1; + buffer[len] = '\0'; + /* * Is it a symbolic ref? */ - if (len < 4) - return -1; - if (!memcmp("ref:", buffer, 4)) { - buf = buffer + 4; - len -= 4; - while (len && isspace(*buf)) - buf++, len--; - if (len >= 5 && !memcmp("refs/", buf, 5)) + if (skip_prefix(buffer, "ref:", &refname)) { + while (isspace(*refname)) + refname++; + if (starts_with(refname, "refs/")) return 0; } /* * Is this a detached HEAD? */ - if (!get_sha1_hex(buffer, sha1)) + if (!get_oid_hex(buffer, &oid)) return 0; return -1; @@@ -718,7 -715,7 +717,7 @@@ char *expand_user_path(const char *path if (!home) goto return_null; if (real_home) - strbuf_addstr(&user_path, real_path(home)); + strbuf_add_real_path(&user_path, home); else strbuf_addstr(&user_path, home); #ifdef GIT_WINDOWS_NATIVE diff --combined sub-process.c index 6dde5062be,648b3a3943..8d2a1707cf --- a/sub-process.c +++ b/sub-process.c @@@ -6,13 -6,10 +6,13 @@@ #include "pkt-line.h" int cmd2process_cmp(const void *unused_cmp_data, - const struct subprocess_entry *e1, - const struct subprocess_entry *e2, + const void *entry, + const void *entry_or_key, const void *unused_keydata) { + const struct subprocess_entry *e1 = entry; + const struct subprocess_entry *e2 = entry_or_key; + return strcmp(e1->cmd, e2->cmd); } @@@ -77,13 -74,12 +77,12 @@@ int subprocess_start(struct hashmap *ha { int err; struct child_process *process; - const char *argv[] = { cmd, NULL }; entry->cmd = cmd; process = &entry->process; child_process_init(process); - process->argv = argv; + argv_array_push(&process->args, cmd); process->use_shell = 1; process->in = -1; process->out = -1; @@@ -184,8 -180,8 +183,8 @@@ static int handshake_capabilities(struc if (supported_capabilities) *supported_capabilities |= capabilities[i].flag; } else { - warning("subprocess '%s' requested unsupported capability '%s'", - process->argv[0], p); + die("subprocess '%s' requested unsupported capability '%s'", + process->argv[0], p); } }