Subject: lib/765: catopen can return 0 on error not -1
To: None <gnats-admin@NetBSD.ORG>
From: John Brezak <brezak@ch.hp.com>
List: netbsd-bugs
Date: 01/29/1995 05:35:04
>Number: 765
>Category: lib
>Synopsis: catopen can return 0 on error not -1
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jan 29 05:35:02 1995
>Originator: John Brezak
>Organization:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
John Brezak UUCP: uunet!apollo.hp!brezak
Hewlett Packard/Apollo Internet: brezak@ch.hp.com
300 Apollo Drive Phone: (508) 436-4915
Chelmsford, Massachusetts Fax: (508) 436-5103
>Release: 1.0
>Environment:
System: NetBSD sussex 1.0 NetBSD 1.0 (SUSSEX) #187: Sat Jan 28 08:56:31 EST 1995 brezak@sussex:/u1/home/john/src/netbsd/sys/arch/i386/compile/SUSSEX i386
>Description:
There are a few places in catopen() and related subroutines that will return
0 on error.
>How-To-Repeat:
Inspect the code.
>Fix:
Here is a 'simple' fix; simply change return(0) occurances to return(NLERR),
but there should be some errno tuning and Posix'izing... The man page should
be tuned up to reflect the errno's used on error.
*** nls/msgcat.c.orig Sat Jan 28 23:42:04 1995
--- nls/msgcat.c Sat Jan 28 23:44:40 1995
***************
*** 96,102 ****
if (strchr(name, '/')) {
catpath = name;
! if (stat(catpath, &sbuf)) return(0);
} else {
if ((lang = (char *) getenv("LANG")) == NULL) lang = "C";
if ((nlspath = (char *) getenv("NLSPATH")) == NULL) {
--- 96,102 ----
if (strchr(name, '/')) {
catpath = name;
! if (stat(catpath, &sbuf)) return(NLERR);
} else {
if ((lang = (char *) getenv("LANG")) == NULL) lang = "C";
if ((nlspath = (char *) getenv("NLSPATH")) == NULL) {
***************
*** 146,152 ****
free(base);
if (tmppath) free(tmppath);
! if (!catpath) return(0);
}
return(loadCat(catpath, type));
--- 146,152 ----
free(base);
if (tmppath) free(tmppath);
! if (!catpath) return(NLERR);
}
return(loadCat(catpath, type));
***************
*** 291,297 ****
/* Note that only malloc failures are allowed to return an error */
#define ERRNAME "Message Catalog System"
! #define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); return(0);}
#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); return(NLERR);}
static nl_catd loadCat( catpath, type)
--- 291,297 ----
/* Note that only malloc failures are allowed to return an error */
#define ERRNAME "Message Catalog System"
! #define CORRUPT() {fprintf(stderr, "%s: corrupt file.\n", ERRNAME); return(NLERR);}
#define NOSPACE() {fprintf(stderr, "%s: no more memory.\n", ERRNAME); return(NLERR);}
static nl_catd loadCat( catpath, type)
***************
*** 310,316 ****
cat->loadType = type;
if ((cat->fd = open(catpath, O_RDONLY)) < 0) {
! return(0);
}
fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
--- 310,316 ----
cat->loadType = type;
if ((cat->fd = open(catpath, O_RDONLY)) < 0) {
! return(NLERR);
}
fcntl(cat->fd, F_SETFD, FD_CLOEXEC);
***************
*** 322,334 ****
if (header.majorVer != MCMajorVer) {
fprintf(stderr, "%s: %s is version %d, we need %d.\n", ERRNAME,
catpath, header.majorVer, MCMajorVer);
! return(0);
}
if (header.numSets <= 0) {
fprintf(stderr, "%s: %s has %d sets!\n", ERRNAME, catpath,
header.numSets);
! return(0);
}
cat->numSets = header.numSets;
--- 322,334 ----
if (header.majorVer != MCMajorVer) {
fprintf(stderr, "%s: %s is version %d, we need %d.\n", ERRNAME,
catpath, header.majorVer, MCMajorVer);
! return(NLERR);
}
if (header.numSets <= 0) {
fprintf(stderr, "%s: %s has %d sets!\n", ERRNAME, catpath,
header.numSets);
! return(NLERR);
}
cat->numSets = header.numSets;
>Audit-Trail:
>Unformatted:
catopen can return 0 on error not -1