Merge branch 'dt/xgethostname-nul-termination'
gethostname(2) may not NUL terminate the buffer if hostname does not fit; unfortunately there is no easy way to see if our buffer was too small, but at least this will make sure we will not end up using garbage past the end of the buffer. * dt/xgethostname-nul-termination: xgethostname: handle long hostnames use HOST_NAME_MAX to size buffers for gethostname(2)
This commit is contained in:
@ -1697,12 +1697,12 @@ static const char *unpack(int err_fd, struct shallow_info *si)
|
||||
if (status)
|
||||
return "unpack-objects abnormal exit";
|
||||
} else {
|
||||
char hostname[256];
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
|
||||
argv_array_pushl(&child.args, "index-pack", "--stdin", NULL);
|
||||
push_header_arg(&child.args, &hdr);
|
||||
|
||||
if (gethostname(hostname, sizeof(hostname)))
|
||||
if (xgethostname(hostname, sizeof(hostname)))
|
||||
xsnprintf(hostname, sizeof(hostname), "localhost");
|
||||
argv_array_pushf(&child.args,
|
||||
"--keep=receive-pack %"PRIuMAX" on %s",
|
||||
|
Reference in New Issue
Block a user