diff options
author | Michael Schroeder <mls@suse.de> | 2019-10-21 11:52:52 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2019-11-18 12:46:29 +0200 |
commit | e2f70fc1d26efa72009048fa1e1de5660cd2e25b (patch) | |
tree | cbf45ce23e6d1a7c427e57a66450cc76088f4c81 | |
parent | 6323eab05d40e9d357cfe7bf5c2da215ffdd05d0 (diff) | |
download | rpm-e2f70fc1d26efa72009048fa1e1de5660cd2e25b.tar.gz |
Multiple fixes in rpmxdb.c for the ndb database backend
Found by torture-testing the ndb database.
* Usedslots was allocated with the wrong size
This did not matter for rpm because rpm uses only a small
number of index databases
* The addslotpage function did not enqueue the new free slots correctly
It never gets called in rpm
* The protection bits were not set if moveblobto needed to map a blob
This can happen if it is called from the moveblobstofront() function,
it will just not shrink the database in the current call.
(cherry picked from commit 62e6a750710293dde19d6de5e804f22601238b01)
-rw-r--r-- | lib/backend/ndb/rpmxdb.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/backend/ndb/rpmxdb.c b/lib/backend/ndb/rpmxdb.c index c67c80cfd..2f94491e9 100644 --- a/lib/backend/ndb/rpmxdb.c +++ b/lib/backend/ndb/rpmxdb.c @@ -274,7 +274,7 @@ static int rpmxdbReadHeader(rpmxdb xdb) xdb->firstfree = 0; nslots = slotnpages * (pagesize / SLOT_SIZE) - SLOT_START + 1; slots = xcalloc(nslots + 1, sizeof(struct xdb_slot)); - usedslots = xcalloc(nslots + 1, sizeof(int)); + usedslots = xcalloc(nslots + 1, sizeof(struct xdb_slot *)); nused = 0; slotno = 1; slot = slots + 1; @@ -615,6 +615,7 @@ static int moveblobto(rpmxdb xdb, struct xdb_slot *oldslot, struct xdb_slot *aft didmap = 0; oldpagecnt = oldslot->pagecnt; if (!oldslot->mapped && oldpagecnt) { + oldslot->mapflags = PROT_READ; if (mapslot(xdb, oldslot)) return RPMRC_FAIL; didmap = 1; @@ -786,13 +787,16 @@ static int addslotpage(rpmxdb xdb) *slot = xdb->slots[nslots]; slot->slotno = nslots + spp; xdb->slots[slot->prev].next = slot->slotno; + + /* we have a new slotpage */ xdb->nslots += spp; + xdb->slots[0].pagecnt++; /* add new free slots to the firstfree chain */ memset(xdb->slots + nslots, 0, sizeof(*slot) * spp); for (i = 0; i < spp - 1; i++) { xdb->slots[nslots + i].slotno = nslots + i; - xdb->slots[nslots + i].next = i + 1; + xdb->slots[nslots + i].next = nslots + i + 1; } xdb->slots[nslots + i].slotno = nslots + i; xdb->firstfree = nslots; |