NetBSD Problem Report #765

From gnats  Sun Jan 29 05:21:39 1995
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id FAA00158 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Sun, 29 Jan 1995 05:21:38 -0800
Message-Id: <199501291303.IAA00509@sussex.hudson.ma.us>
Date: Sun, 29 Jan 1995 08:03:56 -0500
From: John Brezak <brezak@ch.hp.com>
Reply-To: brezak@ch.hp.com
To: gnats-bugs@NetBSD.ORG
Subject: catopen can return 0 on error not -1
X-Send-Pr-Version: 3.2

>Number:         765
>Category:       lib
>Synopsis:       catopen can return 0 on error not -1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          mistaken
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 29 05:35:02 +0000 1995
>Closed-Date:    Wed Mar 01 00:14:55 +0000 1995
>Last-Modified:  
>Originator:     John Brezak
>Release:        1.0
>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
>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;

>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: jtc
State-Changed-When: Wed Mar  1 00:14:55 1995
State-Changed-Why:
This is not a bug (at least not in the code).

XPG3 limits the error conditions so that -1 is only returned in out of
memory (ENOMEM) conditions.  0 is returned for all other errors.  

catgets "knows" that nl_catd 0 is special, and returns the default message.
catclose "knows" not to close nl_catd 0.

>Unformatted:



 catopen can return 0 on error not -1

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.