From owner-cvs-all@FreeBSD.ORG Tue Aug 19 13:38:45 2003 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 76ED616A4BF; Tue, 19 Aug 2003 13:38:45 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1733243FBF; Tue, 19 Aug 2003 13:38:45 -0700 (PDT) (envelope-from wollman@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h7JKci0U081052; Tue, 19 Aug 2003 13:38:44 -0700 (PDT) (envelope-from wollman@repoman.freebsd.org) Received: (from wollman@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h7JKcisC081051; Tue, 19 Aug 2003 13:38:44 -0700 (PDT) Message-Id: <200308192038.h7JKcisC081051@repoman.freebsd.org> From: Garrett Wollman Date: Tue, 19 Aug 2003 13:38:44 -0700 (PDT) To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Subject: cvs commit: src/lib/libc/gen gethostname.3 gethostname.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Aug 2003 20:38:46 -0000 wollman 2003/08/19 13:38:44 PDT FreeBSD src repository Modified files: lib/libc/gen gethostname.3 gethostname.c Log: Change gethostname() to set errno to ENAMETOOLONG instead of ENOMEM when the buffer is not long enough to hold the current host name. POSIX does not standardize error returns for gethostname(), so it doesn't matter which one we use, but ENAMETOOLONG is at least a little more intuitive, and mi suggests the existence of prior art. I've been running with this change for a while on my home machine with no effect. At the same time, I've updated the prototype for gethostname() to use the correct standard type (size_t) for the namelen argument. All of the in-tree callers fall into one of the following categories: 1) Call perror() or equivalent when gethostname() fails. 2) Ignore gethostname()'s return value entirely, potentially resulting in data corruption if the buffer is too small. 3) Fall back to a (possibly sensible) default value if gethostname() fails. Many of the callers I examined shows signs of confusion about the correct sizing of the host name buffer. gethostname(3) now has more information about this, as well as updated standards information. PR: 48114 Submitted by: mi (in part) Revision Changes Path 1.14 +44 -14 src/lib/libc/gen/gethostname.3 1.4 +7 -4 src/lib/libc/gen/gethostname.c