Use MAXHOSTNAMELEN+1 when allocating host/domain name since some

systems do not include space for the NUL in the size.  Also manually
NUL-terminate buffer from gethostname() since POSIX is wishy-washy on this.
This commit is contained in:
Todd C. Miller
2008-10-29 17:26:42 +00:00
parent 9b5e94cef9
commit efb510a9dc
3 changed files with 7 additions and 4 deletions

View File

@@ -793,8 +793,8 @@ netgr_matches(netgr, lhost, shost, user)
#ifdef HAVE_GETDOMAINNAME
/* get the domain name (if any) */
if (!initialized) {
domain = (char *) emalloc(MAXHOSTNAMELEN);
if (getdomainname(domain, MAXHOSTNAMELEN) == -1 || *domain == '\0') {
domain = (char *) emalloc(MAXHOSTNAMELEN + 1);
if (getdomainname(domain, MAXHOSTNAMELEN + 1) == -1 || *domain == '\0') {
efree(domain);
domain = NULL;
}