Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Dec 1997 10:59:08 -0800 (PST)
From:      mjacob@FreeBSD.ORG
To:        freebsd-gnats-submit@FreeBSD.ORG
Subject:   bin/5253: catgets(3) and catclose(3) don't guard against unopened catalogs
Message-ID:  <199712081859.KAA29352@hub.freebsd.org>
Resent-Message-ID: <199712081900.LAA29491@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         5253
>Category:       bin
>Synopsis:       catgets(3) and catclose(3) don't guard against unopened catalogs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec  8 11:00:00 PST 1997
>Last-Modified:
>Originator:     Matthew Jacob
>Organization:
Feral Software
>Release:        2.2.2
>Environment:
FreeBSD worp.feral.com 2.2.2-RELEASE FreeBSD 2.2.2-RELEASE #21: Mon Aug 11 11:17:23 PDT 1997     root@worp.feral.com:/usr/src/sys/compile/WORP  i386

>Description:
catopen(3) defines that a failure to open a message catalog shall
return a nl_catd descriptor of -1.

Most platforms that support catalogs then also handle the case of
a -1 nl_catd descriptor being passed to catgets && catclose (and do
the right thing).

This is mostly a problem for ports of s/w from other systems.

Also, on closer examination, there's a couple other problems in
msgcat.c itself too.
>How-To-Repeat:
Try any catgets or catclose call with -1 as the catalog descriptor.

>Fix:
Index: msgcat.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/nls/msgcat.c,v
retrieving revision 1.11
diff -u -r1.11 msgcat.c
--- msgcat.c    1997/05/10 04:40:40     1.11
+++ msgcat.c    1997/12/08 18:56:22
@@ -85,6 +85,7 @@
 __const char *name;
 int type;
 {
+    nl_catd    rv;
     char       path[MAXPATHLEN];
     __const char *catpath = NULL;
     char        *nlspath;
@@ -93,11 +94,17 @@
     char       *base, *cptr, *pathP;
     struct stat        sbuf;

-    if (!name || !*name) return(NLERR);
+    if (!name || !*name) {
+       errno = EINVAL;
+       return(NLERR);
+    }

     if (strchr(name, '/')) {
        catpath = name;
-       if (stat(catpath, &sbuf)) return(0);
+       if (stat(catpath, &sbuf)) {
+               /* propagate errno back */
+               return (NLERR);
+       }
     } else {
        if ((lang = (char *) getenv("LANG")) == NULL)
                lang = "C";
@@ -106,7 +113,11 @@

        len = strlen(nlspath);
        base = cptr = (char *) malloc(len + 2);
-       if (!base) return(NLERR);
+       if (!base) {
+               if (errno == 0)
+                       errno = ENOMEM;
+               return (NLERR);
+       }
        strcpy(cptr, nlspath);
        cptr[len] = ':';
        cptr[len+1] = '\0';
@@ -137,10 +148,19 @@
        }
        free(base);

-       if (!catpath) return(0);
+       if (!catpath) {
+               errno = ENOENT;
+               return (NLERR);
+       }
     }

-    return(loadCat(catpath, type));
+    rv = loadCat(catpath, type);
+    if (rv == (nl_catd) 0) {
+       if (errno == 0)
+          errno = ENOENT;      /* ?? */
+       rv = NLERR;
+    }
+    return (rv);
 }

 /*
@@ -244,9 +264,14 @@
 char *dflt;
 {
     MCMsgT     *msg;
-    MCCatT     *cat = (MCCatT *) catd;
+    MCCatT     *cat;
     char       *cptr;

+    if (catd == NLERR) {
+       errno = EBADF;
+       return (-1);
+    }
+    cat = (MCCatT *) catd;
     msg = MCGetMsg(MCGetSet(cat, setId), msgId);
     if (msg) cptr = msg->msg.str;
     else cptr = dflt;
@@ -257,11 +282,20 @@
 int            _catclose( catd)
 nl_catd catd;
 {
-    MCCatT     *cat = (MCCatT *) catd;
+    MCCatT     *cat;
+
     MCSetT     *set;
     int                i;

-    if (!cat) return -1;
+    if (catd == NLERR) {
+       errno = EBADF;
+       return (-1);
+    }
+    cat = (MCCatT *) catd;
+    if (!cat) {
+       errno = EBADF;
+       return -1;
+    }

     if (cat->loadType != MCLoadAll) close(cat->fd);
     for (i = 0; i < cat->numSets; ++i) {

>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712081859.KAA29352>