From owner-freebsd-standards@FreeBSD.ORG Wed Oct 17 05:40:00 2012 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C6D9B3F2 for ; Wed, 17 Oct 2012 05:40:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [8.8.178.135]) by mx1.freebsd.org (Postfix) with ESMTP id 9A6698FC1D for ; Wed, 17 Oct 2012 05:40:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q9H5e0g2049993 for ; Wed, 17 Oct 2012 05:40:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q9H5e08k049992; Wed, 17 Oct 2012 05:40:00 GMT (envelope-from gnats) Resent-Date: Wed, 17 Oct 2012 05:40:00 GMT Resent-Message-Id: <201210170540.q9H5e08k049992@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Zhihao Yuan Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A9E6CC4 for ; Wed, 17 Oct 2012 05:30:35 +0000 (UTC) (envelope-from lichray@gmail.com) Received: from mail-ia0-f182.google.com (mail-ia0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id 6D9AE8FC14 for ; Wed, 17 Oct 2012 05:30:35 +0000 (UTC) Received: by mail-ia0-f182.google.com with SMTP id k10so6794235iag.13 for ; Tue, 16 Oct 2012 22:30:34 -0700 (PDT) Received: by 10.50.197.169 with SMTP id iv9mr498491igc.32.1350451834602; Tue, 16 Oct 2012 22:30:34 -0700 (PDT) Received: from localhost (md75036d0.tmodns.net. [208.54.80.215]) by mx.google.com with ESMTPS id x7sm10876715igk.8.2012.10.16.22.30.30 (version=SSLv3 cipher=OTHER); Tue, 16 Oct 2012 22:30:33 -0700 (PDT) Message-Id: <507e4279.8728320a.3464.ffffbdbd@mx.google.com> Date: Tue, 16 Oct 2012 22:30:33 -0700 (PDT) From: Zhihao Yuan To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: standards/172805: Fix catopen(3)'s EINVAL usage and document EFTYPE X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Zhihao Yuan List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2012 05:40:00 -0000 >Number: 172805 >Category: standards >Synopsis: Fix catopen(3)'s EINVAL usage and document EFTYPE >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 17 05:40:00 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Zhihao Yuan >Release: FreeBSD 8.3-STABLE amd64 >Organization: Northern Illinois University >Environment: System: FreeBSD elitebook.hp 8.3-STABLE FreeBSD 8.3-STABLE #4 r240363: Tue Sep 11 10:40:15 CDT 2012 lichray@elitebook.hp:/usr/obj/usr/src/sys/HOUKAGO amd64 >Description: 1. catopen("", 0) should set errno to ENOENT; 2. Document EFTYPE. POSIX says nothing about how to report a corrupt catalog. NetBSD and OpenBSD do nothing (errno == 0), while we set EFTYPE. Document it. 3. Fix errno under a rare condition (fstat(2) fails after open(2)). >How-To-Repeat: >Fix: --- catopen3.patch begins here --- diff --git lib/libc/nls/catopen.3 lib/libc/nls/catopen.3 index 7a16ee5..219c2cb 100644 --- lib/libc/nls/catopen.3 +++ lib/libc/nls/catopen.3 @@ -27,7 +27,7 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd February 12, 2005 +.Dd October 17, 2012 .Dt CATOPEN 3 .Os .Sh NAME @@ -132,10 +132,13 @@ Otherwise, (nl_catd) -1 is returned and is set to indicate the error. .Sh ERRORS .Bl -tag -width Er +.It Bq Er EFTYPE +The named message catalog is corrupt. .It Bq Er EINVAL Argument .Fa name -does not point to a valid message catalog, or catalog is corrupt. +points to +.Dv NULL . .It Bq Er ENAMETOOLONG An entire path to the message catalog exceeded 1024 characters. .It Bq Er ENOENT @@ -154,4 +157,4 @@ Insufficient memory is available. The .Fn catopen function conforms to -.St -p1003.1-2001 . +.St -p1003.1-2008 . diff --git lib/libc/nls/msgcat.c lib/libc/nls/msgcat.c index 44b1440..2c77788 100644 --- lib/libc/nls/msgcat.c +++ lib/libc/nls/msgcat.c @@ -119,8 +119,10 @@ catopen(const char *name, int type) char path[PATH_MAX]; /* sanity checking */ - if (name == NULL || *name == '\0') + if (name == NULL) NLRETERR(EINVAL); + if (*name == '\0') + NLRETERR(ENOENT); if (strchr(name, '/') != NULL) /* have a pathname */ @@ -367,6 +369,7 @@ load_msgcat(const char *path, const char *name, const char *lang) struct catentry *np; void *data; int fd; + int saved_errno; /* path/name will never be NULL here */ @@ -390,9 +393,10 @@ load_msgcat(const char *path, const char *name, const char *lang) } if (_fstat(fd, &st) != 0) { + saved_errno = errno; _close(fd); - SAVEFAIL(name, lang, EFTYPE); - NLRETERR(EFTYPE); + SAVEFAIL(name, lang, saved_errno); + NLRETERR(saved_errno); } /* @@ -408,7 +412,7 @@ load_msgcat(const char *path, const char *name, const char *lang) if ((data = mmap(0, (size_t)st.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) { - int saved_errno = errno; + saved_errno = errno; _close(fd); SAVEFAIL(name, lang, saved_errno); NLRETERR(saved_errno); --- catopen3.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: