From: millert Date: Wed, 15 Jan 1997 22:08:15 +0000 (+0000) Subject: From NetBSD: make testdb() fail if database version string has length zero. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2d68270107519326aff21b626d8fa87acd5600a7;p=openbsd From NetBSD: make testdb() fail if database version string has length zero. Also, KNF, b* -> mem*, getopt tests against -1, not EOF, and index -> strchr. Added OpenBSD tags. --- diff --git a/usr.sbin/kvm_mkdb/extern.h b/usr.sbin/kvm_mkdb/extern.h index dd88a591f90..9a46bb5f9d4 100644 --- a/usr.sbin/kvm_mkdb/extern.h +++ b/usr.sbin/kvm_mkdb/extern.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)extern.h 8.1 (Berkeley) 6/6/93 - * $Id: extern.h,v 1.1.1.1 1995/10/18 08:47:39 deraadt Exp $ + * $OpenBSD: extern.h,v 1.2 1997/01/15 22:08:15 millert Exp $ */ void create_knlist __P((char *, DB *)); diff --git a/usr.sbin/kvm_mkdb/kvm_mkdb.c b/usr.sbin/kvm_mkdb/kvm_mkdb.c index 9a2c7589cd9..85012947ce4 100644 --- a/usr.sbin/kvm_mkdb/kvm_mkdb.c +++ b/usr.sbin/kvm_mkdb/kvm_mkdb.c @@ -1,3 +1,5 @@ +/* $OpenBSD: kvm_mkdb.c,v 1.2 1997/01/15 22:08:15 millert Exp $ */ + /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -38,8 +40,11 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)kvm_mkdb.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: kvm_mkdb.c,v 1.1.1.1 1995/10/18 08:47:39 deraadt Exp $"; +#if 0 +static char sccsid[] = "from: @(#)kvm_mkdb.c 8.1 (Berkeley) 6/6/93"; +#else +static char *rcsid = "$OpenBSD: kvm_mkdb.c,v 1.2 1997/01/15 22:08:15 millert Exp $"; +#endif #endif /* not lint */ #include @@ -76,7 +81,7 @@ main(argc, argv) int ch; char *p, *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN]; - while ((ch = getopt(argc, argv, "")) != EOF) + while ((ch = getopt(argc, argv, "")) != -1) switch (ch) { case '?': default: @@ -92,7 +97,7 @@ main(argc, argv) if (testdb()) exit(0); -#define basename(cp) ((p = rindex((cp), '/')) != NULL ? p + 1 : (cp)) +#define basename(cp) ((p = strrchr((cp), '/')) != NULL ? p + 1 : (cp)) nlistpath = argc > 0 ? argv[0] : _PATH_UNIX; nlistname = basename(nlistpath); diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c index d60ce68006a..f148c95a1d8 100644 --- a/usr.sbin/kvm_mkdb/nlist.c +++ b/usr.sbin/kvm_mkdb/nlist.c @@ -1,3 +1,5 @@ +/* $OpenBSD: nlist.c,v 1.6 1997/01/15 22:08:16 millert Exp $ */ + /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -32,8 +34,11 @@ */ #ifndef lint -/*static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: nlist.c,v 1.5 1996/07/31 17:21:47 deraadt Exp $"; +#if 0 +static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93"; +#else +static char *rcsid = "$OpenBSD: nlist.c,v 1.6 1997/01/15 22:08:16 millert Exp $"; +#endif #endif /* not lint */ #include diff --git a/usr.sbin/kvm_mkdb/testdb.c b/usr.sbin/kvm_mkdb/testdb.c index a754bcd0be6..090ed911731 100644 --- a/usr.sbin/kvm_mkdb/testdb.c +++ b/usr.sbin/kvm_mkdb/testdb.c @@ -1,3 +1,5 @@ +/* $OpenBSD: testdb.c,v 1.2 1997/01/15 22:08:17 millert Exp $ */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -32,8 +34,11 @@ */ #ifndef lint -/*static char sccsid[] = "from: @(#)testdb.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: testdb.c,v 1.1.1.1 1995/10/18 08:47:39 deraadt Exp $"; +#if 0 +static char sccsid[] = "from: @(#)testdb.c 8.1 (Berkeley) 6/6/93"; +#else +static char *rcsid = "$OpenBSD: testdb.c,v 1.2 1997/01/15 22:08:17 millert Exp $"; +#endif #endif /* not lint */ #include @@ -68,9 +73,9 @@ testdb() goto close; uf = _PATH_UNIX; - if ((cp = rindex(uf, '/')) != 0) + if ((cp = strrchr(uf, '/')) != 0) uf = cp + 1; - (void) snprintf(dbname, sizeof(dbname), "%skvm_%s.db", _PATH_VARDB, uf); + (void)snprintf(dbname, sizeof(dbname), "%skvm_%s.db", _PATH_VARDB, uf); if ((db = dbopen(dbname, O_RDONLY, 0, DB_HASH, NULL)) == NULL) goto close; @@ -79,9 +84,9 @@ testdb() rec.size = sizeof(VRS_KEY) - 1; if ((db->get)(db, &rec, &rec, 0)) goto close; - if (rec.data == 0 || rec.size > sizeof(dbversion)) + if (rec.data == 0 || rec.size == 0 || rec.size > sizeof(dbversion)) goto close; - bcopy(rec.data, dbversion, rec.size); + (void)memcpy(dbversion, rec.data, rec.size); dbversionlen = rec.size; /* Read version string from kernel memory */ @@ -91,7 +96,7 @@ testdb() goto close; if (rec.data == 0 || rec.size != sizeof(struct nlist)) goto close; - bcopy(rec.data, &nitem, sizeof(nitem)); + (void)memcpy(&nitem, rec.data, sizeof(nitem)); /* * Theoretically possible for lseek to be seeking to -1. Not * that it's something to lie awake nights about, however. @@ -104,7 +109,7 @@ testdb() goto close; /* If they match, we win */ - ret = bcmp(dbversion, kversion, dbversionlen) == 0; + ret = memcmp(kversion, dbversion, dbversionlen) == 0; close: if (kd >= 0) (void)close(kd);