Skip to content

Commit dd5c88a

Browse files
committed
Merge branch 'tg/memfixes' into maint
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
2 parents d9f5ea4 + 2944a94 commit dd5c88a

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
10171017
memcpy(hex, path, 2);
10181018
path += 2;
10191019
path++; /* skip '/' */
1020-
memcpy(hex, path, GIT_SHA1_HEXSZ - 2);
1020+
memcpy(hex + 2, path, GIT_SHA1_HEXSZ - 2);
10211021

10221022
return get_oid_hex(hex, oid);
10231023
}

path.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ static struct strbuf *get_pathname(void)
3333
return sb;
3434
}
3535

36-
static char *cleanup_path(char *path)
36+
static const char *cleanup_path(const char *path)
3737
{
3838
/* Clean it up */
39-
if (!memcmp(path, "./", 2)) {
40-
path += 2;
39+
if (skip_prefix(path, "./", &path)) {
4140
while (*path == '/')
4241
path++;
4342
}
@@ -46,7 +45,7 @@ static char *cleanup_path(char *path)
4645

4746
static void strbuf_cleanup_path(struct strbuf *sb)
4847
{
49-
char *path = cleanup_path(sb->buf);
48+
const char *path = cleanup_path(sb->buf);
5049
if (path > sb->buf)
5150
strbuf_remove(sb, 0, path - sb->buf);
5251
}
@@ -63,7 +62,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)
6362
strlcpy(buf, bad_path, n);
6463
return buf;
6564
}
66-
return cleanup_path(buf);
65+
return (char *)cleanup_path(buf);
6766
}
6867

6968
static int dir_prefix(const char *buf, const char *dir)

sub-process.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
7474
{
7575
int err;
7676
struct child_process *process;
77-
const char *argv[] = { cmd, NULL };
7877

7978
entry->cmd = cmd;
8079
process = &entry->process;
8180

8281
child_process_init(process);
83-
process->argv = argv;
82+
argv_array_push(&process->args, cmd);
8483
process->use_shell = 1;
8584
process->in = -1;
8685
process->out = -1;

0 commit comments

Comments
 (0)