Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/getcap.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.35 retrieving revision 1.46 diff -u -p -r1.35 -r1.46 --- src/lib/libc/gen/getcap.c 2002/04/16 19:07:57 1.35 +++ src/lib/libc/gen/getcap.c 2006/05/29 21:55:41 1.46 @@ -1,4 +1,4 @@ -/* $NetBSD: getcap.c,v 1.35 2002/04/16 19:07:57 groo Exp $ */ +/* $NetBSD: getcap.c,v 1.46 2006/05/29 21:55:41 jnemeth Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,21 +32,30 @@ * SUCH DAMAGE. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #else -__RCSID("$NetBSD: getcap.c,v 1.35 2002/04/16 19:07:57 groo Exp $"); +__RCSID("$NetBSD: getcap.c,v 1.46 2006/05/29 21:55:41 jnemeth Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifndef SMALL #include "namespace.h" +#endif #include +#include #include #include +#ifndef SMALL #include +#endif #include #include #include @@ -86,9 +91,12 @@ static size_t topreclen; /* toprec leng static char *toprec; /* Additional record specified by cgetset() */ static int gottoprec; /* Flag indicating retrieval of toprecord */ -static int cdbget __P((DB *, char **, const char *)); -static int getent __P((char **, size_t *, char **, int, const char *, int, char *)); -static int nfcmp __P((char *, char *)); +#ifndef SMALL +static int cdbget(DB *, char **, const char *); +#endif +static int getent(char **, size_t *, const char * const *, int, + const char *, int, char *); +static int nfcmp(char *, char *); /* * Cgetset() allows the addition of a user specified buffer to be added @@ -96,8 +104,7 @@ static int nfcmp __P((char *, char *)); * virtual database. 0 is returned on success, -1 on failure. */ int -cgetset(ent) - const char *ent; +cgetset(const char *ent) { const char *source, *check; char *dest; @@ -206,10 +213,9 @@ cgetcap(buf, cap, type) * encountered (couldn't open/read a file, etc.), and -3 if a potential * reference loop is detected. */ +/* coverity[+alloc : arg-*0] */ int -cgetent(buf, db_array, name) - char **buf, **db_array; - const char *name; +cgetent(char **buf, const char * const *db_array, const char *name) { size_t dummy; @@ -238,20 +244,23 @@ cgetent(buf, db_array, name) * names interpolated, a name can't be found, or depth exceeds * MAX_RECURSION. */ +/* coverity[+alloc : arg-*0] */ static int -getent(cap, len, db_array, fd, name, depth, nfield) - char **cap, **db_array, *nfield; - const char *name; - size_t *len; - int fd, depth; +getent(char **cap, size_t *len, const char * const *db_array, int fd, + const char *name, int depth, char *nfield) { +#ifndef SMALL DB *capdbp; - char *r_end, *rp = NULL, **db_p; /* pacify gcc */ - int myfd = 0, eof, foundit, retval; + char pbuf[MAXPATHLEN]; + char *cbuf; + int retval; size_t clen; - char *record, *cbuf, *newrecord; +#endif + char *record, *newrecord; + char *r_end, *rp = NULL; /* pacify gcc */ + const char * const *db_p; + int myfd = 0, eof, foundit; int tc_not_resolved; - char pbuf[_POSIX_PATH_MAX]; _DIAGASSERT(cap != NULL); _DIAGASSERT(len != NULL); @@ -304,6 +313,7 @@ getent(cap, len, db_array, fd, name, dep if (fd >= 0) { (void)lseek(fd, (off_t)0, SEEK_SET); } else { +#ifndef SMALL (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) != NULL) { @@ -316,7 +326,11 @@ getent(cap, len, db_array, fd, name, dep } /* save the data; close frees it */ clen = strlen(record); - cbuf = malloc(clen + 1); + if ((cbuf = malloc(clen + 1)) == NULL) { + (void)capdbp->close(capdbp); + errno = ENOMEM; + return (-2); + } memmove(cbuf, record, clen + 1); if (capdbp->close(capdbp) < 0) { int serrno = errno; @@ -328,7 +342,9 @@ getent(cap, len, db_array, fd, name, dep *len = clen; *cap = cbuf; return (retval); - } else { + } else +#endif + { fd = open(*db_p, O_RDONLY, 0); if (fd < 0) { /* No error on unfound file. */ @@ -635,11 +651,9 @@ tc_exp: { return (0); } +#ifndef SMALL static int -cdbget(capdbp, bp, name) - DB *capdbp; - char **bp; - const char *name; +cdbget(DB *capdbp, char **bp, const char *name) { DBT key; DBT data; @@ -648,8 +662,7 @@ cdbget(capdbp, bp, name) _DIAGASSERT(bp != NULL); _DIAGASSERT(name != NULL); - /* LINTED key is not modified */ - key.data = (char *)name; + key.data = __UNCONST(name); key.size = strlen(name); for (;;) { @@ -672,14 +685,14 @@ cdbget(capdbp, bp, name) *bp = (char *)data.data + 1; return (((char *)(data.data))[0] == TCERR ? 1 : 0); } +#endif /* * Cgetmatch will return 0 if name is one of the names of the capability * record buf, -1 if not. */ int -cgetmatch(buf, name) - const char *buf, *name; +cgetmatch(const char *buf, const char *name) { const char *np, *bp; @@ -722,8 +735,7 @@ cgetmatch(buf, name) } int -cgetfirst(buf, db_array) - char **buf, **db_array; +cgetfirst(char **buf, const char * const *db_array) { _DIAGASSERT(buf != NULL); @@ -735,10 +747,10 @@ cgetfirst(buf, db_array) static FILE *pfp; static int slash; -static char **dbp; +static const char * const *dbp; int -cgetclose() +cgetclose(void) { if (pfp != NULL) { (void)fclose(pfp); @@ -755,12 +767,11 @@ cgetclose() * specified by db_array. It returns 0 upon completion of the database, 1 * upon returning an entry with more remaining, and -1 if an error occurs. */ +/* coverity[+alloc : arg-*0] */ int -cgetnext(bp, db_array) - char **bp; - char **db_array; +cgetnext(char **bp, const char * const *db_array) { - size_t len; + size_t len = 0; int status, done; char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; size_t dummy; @@ -781,7 +792,9 @@ cgetnext(bp, db_array) line = toprec; } else { line = fgetln(pfp, &len); - if (line == NULL && pfp) { + if (line == NULL) { + if (pfp == NULL) + return -1; if (ferror(pfp)) { (void)cgetclose(); return (-1); @@ -892,10 +905,7 @@ cgetnext(bp, db_array) * allocation failure). */ int -cgetstr(buf, cap, str) - char *buf; - const char *cap; - char **str; +cgetstr(char *buf, const char *cap, char **str) { u_int m_room; const char *bp; @@ -1030,10 +1040,7 @@ cgetstr(buf, cap, str) * error was encountered (storage allocation failure). */ int -cgetustr(buf, cap, str) - char *buf; - const char *cap; - char **str; +cgetustr(char *buf, const char *cap, char **str) { u_int m_room; const char *bp; @@ -1113,10 +1120,7 @@ cgetustr(buf, cap, str) * numeric capability couldn't be found. */ int -cgetnum(buf, cap, num) - char *buf; - const char *cap; - long *num; +cgetnum(char *buf, const char *cap, long *num) { long n; int base, digit; @@ -1182,8 +1186,7 @@ cgetnum(buf, cap, num) * Compare name field of record. */ static int -nfcmp(nf, rec) - char *nf, *rec; +nfcmp(char *nf, char *rec) { char *cp, tmp; int ret;