From 38bc45fc2277bb8b79fc210a7497a386cebe2798 Mon Sep 17 00:00:00 2001 From: bluhm Date: Mon, 19 Jan 2015 16:40:49 +0000 Subject: [PATCH] Replace HOST_NAME_MAX+1 with NI_MAXHOST when the hostname is used with getaddrinfo() or getnameinfo(), but keep HOST_NAME_MAX+1 when the hostname comes from gethostname(). No binary change; OK deraadt@ --- usr.sbin/syslogd/privsep.c | 12 +++++++----- usr.sbin/syslogd/syslogd.c | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/usr.sbin/syslogd/privsep.c b/usr.sbin/syslogd/privsep.c index 9e527943a41..49c66b5cbbb 100644 --- a/usr.sbin/syslogd/privsep.c +++ b/usr.sbin/syslogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.50 2015/01/16 06:40:21 deraadt Exp $ */ +/* $OpenBSD: privsep.c,v 1.51 2015/01/19 16:40:49 bluhm Exp $ */ /* * Copyright (c) 2003 Anil Madhavapeddy @@ -23,9 +23,11 @@ #include #include #include + #include #include #include +#include #include #include #include @@ -37,7 +39,7 @@ #include #include #include -#include + #include "syslogd.h" /* @@ -103,8 +105,8 @@ priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[]) { int i, fd, socks[2], cmd, addr_len, result, restart; size_t path_len, protoname_len, hostname_len, servname_len; - char path[PATH_MAX], protoname[5], hostname[HOST_NAME_MAX+1]; - char servname[NI_MAXSERV]; + char path[PATH_MAX], protoname[5]; + char hostname[NI_MAXHOST], servname[NI_MAXSERV]; struct sockaddr_storage addr; struct stat cf_stat; struct passwd *pw; @@ -699,7 +701,7 @@ int priv_getaddrinfo(char *proto, char *host, char *serv, struct sockaddr *addr, size_t addr_len) { - char protocpy[5], hostcpy[HOST_NAME_MAX+1], servcpy[NI_MAXSERV]; + char protocpy[5], hostcpy[NI_MAXHOST], servcpy[NI_MAXSERV]; int cmd, ret_len; size_t protoname_len, hostname_len, servname_len; diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 915cba56475..923a86c2677 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.143 2015/01/18 19:37:59 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.144 2015/01/19 16:40:49 bluhm Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -81,10 +81,11 @@ #include #include -#include #include +#include #include #include +#include #include #include #include @@ -93,7 +94,6 @@ #include #include #include -#include #include #include @@ -135,7 +135,7 @@ struct filed { union { char f_uname[MAXUNAMES][UT_NAMESIZE+1]; struct { - char f_loghost[1+4+3+1+HOST_NAME_MAX+1+1+NI_MAXSERV]; + char f_loghost[1+4+3+1+NI_MAXHOST+1+NI_MAXSERV]; /* @proto46://[hostname]:servname\0 */ struct sockaddr_storage f_addr; struct buffertls f_buftls; @@ -653,7 +653,7 @@ udp_readcb(int fd, short event, void *arg) salen = sizeof(sa); n = recvfrom(fd, linebuf, MAXLINE, 0, (struct sockaddr *)&sa, &salen); if (n > 0) { - char resolve[HOST_NAME_MAX+1]; + char resolve[NI_MAXHOST]; linebuf[n] = '\0'; cvthname((struct sockaddr *)&sa, resolve, sizeof(resolve)); @@ -1825,7 +1825,7 @@ cfline(char *line, char *prog) logerror(ebuf); break; } - if (strlen(host) >= HOST_NAME_MAX+1) { + if (strlen(host) >= NI_MAXHOST) { snprintf(ebuf, sizeof(ebuf), "host too long \"%s\"", f->f_un.f_forw.f_loghost); logerror(ebuf); -- 2.20.1