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:
4
ident.c
4
ident.c
@ -120,9 +120,9 @@ static int canonical_name(const char *host, struct strbuf *out)
|
||||
|
||||
static void add_domainname(struct strbuf *out, int *is_bogus)
|
||||
{
|
||||
char buf[1024];
|
||||
char buf[HOST_NAME_MAX + 1];
|
||||
|
||||
if (gethostname(buf, sizeof(buf))) {
|
||||
if (xgethostname(buf, sizeof(buf))) {
|
||||
warning_errno("cannot get host name");
|
||||
strbuf_addstr(out, "(none)");
|
||||
*is_bogus = 1;
|
||||
|
Reference in New Issue
Block a user