From owner-freebsd-bugs Sun Feb 9 12: 0:28 2003 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4956737B401 for ; Sun, 9 Feb 2003 12:00:26 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id B55E243FAF for ; Sun, 9 Feb 2003 12:00:24 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h19K0ONS005239 for ; Sun, 9 Feb 2003 12:00:24 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h19K0OmA005238; Sun, 9 Feb 2003 12:00:24 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED98C37B405 for ; Sun, 9 Feb 2003 11:58:57 -0800 (PST) Received: from aldan.algebra.com (aldan.algebra.com [216.254.65.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id BAF9E43FA3 for ; Sun, 9 Feb 2003 11:58:56 -0800 (PST) (envelope-from mi@aldan.algebra.com) Received: from aldan.algebra.com (localhost [127.0.0.1]) by aldan.algebra.com (8.12.6/8.12.6) with ESMTP id h1982t6P044547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 9 Feb 2003 03:11:03 -0500 (EST) (envelope-from mi@aldan.algebra.com) Received: (from mi@localhost) by aldan.algebra.com (8.12.6/8.12.6/Submit) id h197l5k0044333; Sun, 9 Feb 2003 02:47:05 -0500 (EST) (envelope-from mi) Message-Id: <200302090747.h197l5k0044333@aldan.algebra.com> Date: Sun, 9 Feb 2003 02:47:05 -0500 (EST) From: Mikhail Teterin Reply-To: Mikhail Teterin To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/48114: gethostname(3) can leave the wrong errno Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 48114 >Category: bin >Synopsis: gethostname(3) can leave the wrong errno >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Feb 09 12:00:24 PST 2003 >Closed-Date: >Last-Modified: >Originator: Mikhail Teterin >Release: FreeBSD 5.0-CURRENT i386 >Organization: Virtual Estates, Inc. >Environment: System: FreeBSD aldan.algebra.com 5.0-CURRENT FreeBSD 5.0-CURRENT #2: Sat Feb 8 18:55:41 EST 2003 root@aldan.algebra.com:/ccd/obj/ccd/src/sys/DEBUG i386 >Description: gethostname(3) is known and documented to set errno to the special ENAMETOOLONG in case of the insufficient buffer size. However, sysctl(3)'s value for this case is ENOMEM. As a result, errno after an unsuccessful call to gethostname(3) may have a value unexpected by an application. See, for example, http://www.FreeBSD.org/cgi/query-pr.cgi?pr=ports/30298 >How-To-Repeat: >Fix: How about the following? cvs server: Diffing . Index: gethostname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/gethostname.c,v retrieving revision 1.3 diff -U2 -r1.3 gethostname.c --- gethostname.c 22 Mar 2002 21:52:05 -0000 1.3 +++ gethostname.c 9 Feb 2003 07:43:33 -0000 @@ -52,6 +52,9 @@ mib[1] = KERN_HOSTNAME; size = namelen; - if (sysctl(mib, 2, name, &size, NULL, 0) == -1) + if (sysctl(mib, 2, name, &size, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = ENAMETOOLONG; return (-1); + } return (0); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message