From be0b90359bcd8156385178eb9b570c0538c0333f Mon Sep 17 00:00:00 2001 From: ewt Date: Wed, 29 Jan 1997 17:39:46 +0000 Subject: [PATCH] does some basic sanity checks on headers read from the database CVS patchset: 1375 CVS date: 1997/01/29 17:39:46 --- lib/rebuilddb.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/rebuilddb.c b/lib/rebuilddb.c index 78c9e68..e359141 100644 --- a/lib/rebuilddb.c +++ b/lib/rebuilddb.c @@ -18,7 +18,7 @@ int rpmdbRebuild(char * rootdir) { rpmdb olddb, newdb; char * dbpath, * newdbpath; - unsigned int recnum; + int recnum; Header h; int failed = 0; @@ -57,17 +57,28 @@ int rpmdbRebuild(char * rootdir) { } recnum = rpmdbFirstRecNum(olddb); - while (recnum) { + while (recnum > 0) { if (!(h = rpmdbGetRecord(olddb, recnum))) { rpmError(RPMERR_INTERNAL, "cannot read database record at %d", recnum); failed = 1; break; } - if (rpmdbAdd(newdb, h)) { - rpmError(RPMERR_INTERNAL, "cannot add record originally at %d", - recnum); - failed = 1; - break; + + /* let's sanity check this record a bit, otherwise just skip it */ + if (headerIsEntry(h, RPMTAG_NAME) && + headerIsEntry(h, RPMTAG_VERSION) && + headerIsEntry(h, RPMTAG_RELEASE) && + headerIsEntry(h, RPMTAG_RELEASE) && + headerIsEntry(h, RPMTAG_BUILDTIME)) { + if (rpmdbAdd(newdb, h)) { + rpmError(RPMERR_INTERNAL, "cannot add record originally at %d", + recnum); + failed = 1; + break; + } + } else { + rpmError(RPMERR_INTERNAL, "record number %d in database is bad " + "-- skipping it", recnum); } recnum = rpmdbNextRecNum(olddb, recnum); } -- 2.7.4