Merge branch 'dt/xgethostname-nul-termination'
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Apr 2017 05:07:57 +0000 (22:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Apr 2017 05:07:57 +0000 (22:07 -0700)
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)

1  2 
builtin/gc.c
builtin/receive-pack.c
daemon.c
fetch-pack.c
git-compat-util.h
ident.c
wrapper.c
diff --cc builtin/gc.c
Simple merge
index 7f484e7f6b41be0555babb54ba8853d0bf1e4269,eee5faaa244ec0252305adbeddf7d5c5fa2d4eb0..f96834f42c9849746b64c20c84869232cbac7367
@@@ -1697,12 -1655,12 +1697,12 @@@ static const char *unpack(int err_fd, s
                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", hdr_arg, NULL);
 +              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",
diff --cc daemon.c
Simple merge
diff --cc fetch-pack.c
Simple merge
Simple merge
diff --cc ident.c
Simple merge
diff --cc wrapper.c
Simple merge