SHA256
3
0
forked from pool/rpm

- rework header data handling in ndb's glue code [bnc#1179416]

OBS-URL: https://build.opensuse.org/package/show/Base:System/rpm?expand=0&rev=564
This commit is contained in:
Michael Schröder 2020-12-21 15:31:25 +00:00 committed by Git OBS Bridge
parent 1d294edb3a
commit 30e44e5b0f
3 changed files with 143 additions and 1 deletions

135
ndbglue.diff Normal file
View File

@ -0,0 +1,135 @@
--- ./lib/backend/ndb/glue.c.orig
+++ ./lib/backend/ndb/glue.c
@@ -19,6 +19,8 @@ struct dbiCursor_s {
const void *key;
unsigned int keylen;
unsigned int hdrNum;
+ void *data;
+ unsigned int datalen;
int flags;
unsigned int *list;
@@ -33,7 +35,7 @@ struct ndbEnv_s {
int refs;
int dofsync;
- unsigned int hdrNum;
+ unsigned int hdrNum; /* free for adoption */
void *data;
unsigned int datalen;
};
@@ -278,6 +280,40 @@ static int ndb_Ctrl(rpmdb rdb, dbCtrlOp ctrl)
return 0;
}
+static void setenvdata(struct ndbEnv_s *ndbenv, unsigned int hdrNum, unsigned char *hdrBlob, unsigned int hdrLen)
+{
+ if (ndbenv->data)
+ free(ndbenv->data);
+ ndbenv->hdrNum = hdrNum;
+ ndbenv->data = hdrBlob;
+ ndbenv->datalen = hdrLen;
+}
+
+static void setdata(dbiCursor dbc, unsigned int hdrNum, unsigned char *hdrBlob, unsigned int hdrLen)
+{
+ struct ndbEnv_s *ndbenv = dbc->dbi->dbi_rpmdb->db_dbenv;
+ if (ndbenv->data)
+ setenvdata(ndbenv, 0, 0, 0); /* clear dbenv cache */
+ if (dbc->data)
+ free(dbc->data);
+ dbc->hdrNum = hdrNum;
+ dbc->data = hdrBlob;
+ dbc->datalen = hdrLen;
+}
+
+static void adoptdata(dbiCursor dbc)
+{
+ struct ndbEnv_s *ndbenv = dbc->dbi->dbi_rpmdb->db_dbenv;
+ if (dbc->data)
+ free(dbc->data);
+ dbc->hdrNum = ndbenv->hdrNum;
+ dbc->data = ndbenv->data;
+ dbc->datalen = ndbenv->datalen;
+ ndbenv->hdrNum = 0;
+ ndbenv->data = 0;
+ ndbenv->datalen = 0;
+}
+
static dbiCursor ndb_CursorInit(dbiIndex dbi, unsigned int flags)
{
dbiCursor dbc = xcalloc(1, sizeof(*dbc));
@@ -293,21 +329,17 @@ static dbiCursor ndb_CursorFree(dbiIndex dbi, dbiCursor dbc)
free(dbc->list);
if (dbc->listdata)
free(dbc->listdata);
+ if (dbc->data) {
+ /* release data into dbenv so that the next cursor can adopt it */
+ struct ndbEnv_s *ndbenv = dbc->dbi->dbi_rpmdb->db_dbenv;
+ setenvdata(ndbenv, dbc->hdrNum, dbc->data, dbc->datalen);
+ }
free(dbc);
}
return NULL;
}
-static void setdata(dbiCursor dbc, unsigned int hdrNum, unsigned char *hdrBlob, unsigned int hdrLen)
-{
- struct ndbEnv_s *ndbenv = dbc->dbi->dbi_rpmdb->db_dbenv;
- if (ndbenv->data)
- free(ndbenv->data);
- ndbenv->hdrNum = hdrNum;
- ndbenv->data = hdrBlob;
- ndbenv->datalen = hdrLen;
-}
static rpmRC ndb_pkgdbPut(dbiIndex dbi, dbiCursor dbc, unsigned int *hdrNum, unsigned char *hdrBlob, unsigned int hdrLen)
{
@@ -324,7 +356,6 @@ static rpmRC ndb_pkgdbPut(dbiIndex dbi, dbiCursor dbc, unsigned int *hdrNum, un
rc = rpmpkgPut(dbc->dbi->dbi_db, hnum, hdrBlob, hdrLen);
if (!rc) {
- dbc->hdrNum = hnum;
setdata(dbc, hnum, 0, 0);
*hdrNum = hnum;
}
@@ -333,7 +364,6 @@ static rpmRC ndb_pkgdbPut(dbiIndex dbi, dbiCursor dbc, unsigned int *hdrNum, un
static rpmRC ndb_pkgdbDel(dbiIndex dbi, dbiCursor dbc, unsigned int hdrNum)
{
- dbc->hdrNum = 0;
setdata(dbc, 0, 0, 0);
return rpmpkgDel(dbc->dbi->dbi_db, hdrNum);
}
@@ -362,7 +392,6 @@ static rpmRC ndb_pkgdbIter(dbiIndex dbi, dbiCursor dbc, unsigned char **hdrBlob,
break;
dbc->ilist++;
if (!rc) {
- dbc->hdrNum = hdrNum;
setdata(dbc, hdrNum, *hdrBlob, *hdrLen);
break;
}
@@ -377,16 +406,16 @@ static rpmRC ndb_pkgdbGet(dbiIndex dbi, dbiCursor dbc, unsigned int hdrNum, unsi
if (!hdrNum)
return ndb_pkgdbIter(dbi, dbc, hdrBlob, hdrLen);
- if (hdrNum == ndbenv->hdrNum && ndbenv->data) {
- *hdrBlob = ndbenv->data;
- *hdrLen = ndbenv->datalen;
+ if (!dbc->data && ndbenv->data)
+ adoptdata(dbc);
+ if (dbc->data && hdrNum == dbc->hdrNum) {
+ *hdrBlob = dbc->data;
+ *hdrLen = dbc->datalen;
return RPMRC_OK;
}
rc = rpmpkgGet(dbc->dbi->dbi_db, hdrNum, hdrBlob, hdrLen);
- if (!rc) {
- dbc->hdrNum = hdrNum;
+ if (!rc)
setdata(dbc, hdrNum, *hdrBlob, *hdrLen);
- }
return rc;
}

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Dec 21 16:29:40 CET 2020 - mls@suse.de
- rework header data handling in ndb's glue code [bnc#1179416]
* new patch: ndbglue.diff
-------------------------------------------------------------------
Wed Nov 18 10:46:03 CET 2020 - mls@suse.de

View File

@ -128,6 +128,7 @@ Patch122: db_conversion.diff
Patch123: nextiteratorheaderblob.diff
Patch127: finddebuginfo-check-res-file.patch
Patch128: empty_dbbackend.diff
Patch129: ndbglue.diff
Patch6464: auto-config-update-aarch64-ppc64le.diff
BuildRoot: %{_tmppath}/%{name}-%{version}-build
#
@ -252,7 +253,7 @@ cp config.guess config.sub db/dist/
%patch -P 93 -P 94 -P 99
%patch -P 100 -P 102 -P 103
%patch -P 109 -P 117
%patch -P 122 -P 123 -P 127 -P 128
%patch -P 122 -P 123 -P 127 -P 128 -P 129
%ifarch aarch64 ppc64le riscv64
%patch6464