From: René Scharfe Date: Wed, 19 Apr 2017 14:03:19 GMT Subject: Re: [PATCH v3 1/2] use HOST_NAME_MAX to size buffers for gethostname(2) Message-ID: <269cbe1c-d10a-7022-1977-2128d59aebb3@web.de> In-Reply-To: <20170419012824.GA28740@aiede.svl.corp.google.com> Am 19.04.2017 um 03:28 schrieb Jonathan Nieder: >> From: René Scharfe >> >> POSIX limits the length of host names to HOST_NAME_MAX. Export the >> fallback definition from daemon.c and use this constant to make all >> buffers used with gethostname(2) big enough for any possible result >> and a terminating NUL. > > Since some platforms do not define HOST_NAME_MAX and we provide a > fallback, this is not actually big enough for any possible result. > For example, the Hurd allows arbitrarily long hostnames. Interesting. No limits, eh? They suggest to allocate memory dynamically [1]. Perhaps we should import their xgethostname() (which grows a buffer as needed), or implement a strbuf_add_hostname()? René https://www.gnu.org/software/hurd/hurd/porting/guidelines.html#MAXHOSTNAMELEN_tt_