Date: Sun, 9 Feb 2003 02:47:05 -0500 (EST) From: Mikhail Teterin <mi@aldan.algebra.com> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/48114: gethostname(3) can leave the wrong errno Message-ID: <200302090747.h197l5k0044333@aldan.algebra.com>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302090747.h197l5k0044333>