From: Todd C. Miller Date: Tue, 4 Dec 2012 15:18:41 +0000 (-0500) Subject: Use MAX_HOST_NAME+1 (limits.h) instead of MAXHOSTNAMELEN (sys/param.h X-Git-Tag: SUDO_1_8_7~1^2~301 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c9da162e4ab29ca69f59e2141453892ced67a5a;p=sudo Use MAX_HOST_NAME+1 (limits.h) instead of MAXHOSTNAMELEN (sys/param.h or netdb.h). --- diff --git a/include/missing.h b/include/missing.h index fda151bf7..1cd16e5b9 100644 --- a/include/missing.h +++ b/include/missing.h @@ -93,8 +93,16 @@ # endif #endif -#ifndef MAXHOSTNAMELEN -# define MAXHOSTNAMELEN 64 +#ifndef HOST_NAME_MAX +# ifdef MAXHOSTNAMELEN +# define HOST_NAME_MAX MAXHOSTNAMELEN +# else +# ifdef _POSIX_HOST_NAME_MAX +# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX +# else +# define HOST_NAME_MAX 64 +# endif +# endif #endif /* diff --git a/plugins/sudoers/match.c b/plugins/sudoers/match.c index f7b69689e..45c4090c9 100644 --- a/plugins/sudoers/match.c +++ b/plugins/sudoers/match.c @@ -788,8 +788,8 @@ netgr_matches(char *netgr, char *lhost, char *shost, char *user) #ifdef HAVE_GETDOMAINNAME /* get the domain name (if any) */ if (!initialized) { - domain = (char *) emalloc(MAXHOSTNAMELEN + 1); - if (getdomainname(domain, MAXHOSTNAMELEN + 1) == -1 || *domain == '\0') { + domain = (char *) emalloc(HOST_NAME_MAX + 1); + if (getdomainname(domain, HOST_NAME_MAX + 1) == -1 || *domain == '\0') { efree(domain); domain = NULL; } diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index bf1a16aab..f7678de01 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -128,7 +128,7 @@ main(int argc, char *argv[]) struct privilege *priv; struct userspec *us; char *p, *grfile, *pwfile; - char hbuf[MAXHOSTNAMELEN + 1]; + char hbuf[HOST_NAME_MAX + 1]; int match, host_match, runas_match, cmnd_match; int ch, dflag, exitcode = 0; debug_decl(main, SUDO_DEBUG_MAIN) diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 6ed97edd0..f9f92bc3a 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -1040,7 +1040,7 @@ get_args(char *cmnd) static void get_hostname(void) { - char *p, thost[MAXHOSTNAMELEN + 1]; + char *p, thost[HOST_NAME_MAX + 1]; debug_decl(get_hostname, SUDO_DEBUG_UTIL) if (gethostname(thost, sizeof(thost)) != -1) { diff --git a/src/sudo.c b/src/sudo.c index 9d947a84e..1e28e870e 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -414,7 +414,7 @@ get_user_groups(struct user_details *ud) static char ** get_user_info(struct user_details *ud) { - char *cp, **user_info, cwd[PATH_MAX], host[MAXHOSTNAMELEN]; + char *cp, **user_info, cwd[PATH_MAX], host[HOST_NAME_MAX + 1]; struct passwd *pw; int fd, i = 0; debug_decl(get_user_info, SUDO_DEBUG_UTIL)