xgethostname: handle long hostnames
If the full hostname doesn't fit in the buffer supplied to gethostname, POSIX does not specify whether the buffer will be null-terminated, so to be safe, we should do it ourselves. Introduce new function, xgethostname, which ensures that there is always a \0 at the end of the buffer. Signed-off-by: David Turner <dturner@twosigma.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
da25bdb776
commit
5781a9a270
@ -232,7 +232,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
|
||||
/* already locked */
|
||||
return NULL;
|
||||
|
||||
if (gethostname(my_host, sizeof(my_host)))
|
||||
if (xgethostname(my_host, sizeof(my_host)))
|
||||
xsnprintf(my_host, sizeof(my_host), "unknown");
|
||||
|
||||
pidfile_path = git_pathdup("gc.pid");
|
||||
|
||||
Reference in New Issue
Block a user