diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-01-28 17:07:42 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-01-28 17:07:42 +0200 |
commit | 06a2f1269b035a3a76464149834f2a5a8c4e89f2 (patch) | |
tree | d5d11a7900d974196484e2ad984321a8e6d47298 | |
parent | 5e4fb2589ca19b7844f420affe9977c04a124469 (diff) | |
download | librpm-tizen-06a2f1269b035a3a76464149834f2a5a8c4e89f2.tar.gz librpm-tizen-06a2f1269b035a3a76464149834f2a5a8c4e89f2.tar.bz2 librpm-tizen-06a2f1269b035a3a76464149834f2a5a8c4e89f2.zip |
Don't assume rpmfiNew() always succeeds
- Add NULL checks and add/adjust comments where appropriate.
- The remaining callers should handle NULL fi gracefully if not
entirely correctly: rpmfiFC() returns 0 on NULL fi, so these
callers just see the erronous file info set as "no files" case.
Something to fine-tune later...
-rw-r--r-- | build/files.c | 11 | ||||
-rw-r--r-- | lib/psm.c | 2 | ||||
-rw-r--r-- | lib/rpmte.c | 6 | ||||
-rw-r--r-- | lib/transaction.c | 1 | ||||
-rw-r--r-- | lib/verify.c | 3 | ||||
-rw-r--r-- | python/rpmfi-py.c | 5 |
6 files changed, 25 insertions, 3 deletions
diff --git a/build/files.c b/build/files.c index f222a5dfa..64344f7d5 100644 --- a/build/files.c +++ b/build/files.c @@ -1239,6 +1239,9 @@ static void genCpioListAndHeader(FileList fl, headerConvert(h, HEADERCONV_COMPRESSFILELIST); fi = rpmfiNew(NULL, h, RPMTAG_BASENAMES, flags); + if (fi == NULL) + return; + /* * Grab the real filenames from ORIGFILENAMES and put into OLDFILENAMES, * remove temporary cruft and side-effects from filelist compression @@ -1896,6 +1899,8 @@ static rpmRC processPackageFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags, "PartialHardlinkSets", "4.0.4-1"); genCpioListAndHeader(&fl, &pkg->cpioList, pkg->header, 0); + if (pkg->cpioList == NULL) + fl.processingFailed = 1; exit: fl.buildRoot = _free(fl.buildRoot); @@ -2031,9 +2036,13 @@ rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags) argvFree(files); if (! fl.processingFailed) { - if (spec->sourceHeader != NULL) + if (spec->sourceHeader != NULL) { genCpioListAndHeader(&fl, &spec->sourceCpioList, spec->sourceHeader, 1); + if (spec->sourceCpioList == NULL) { + fl.processingFailed = 1; + } + } } fl.fileList = freeFileList(fl.fileList, fl.fileListRecsUsed); @@ -322,7 +322,7 @@ rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); h = headerFree(h); - if (fi == NULL) { /* XXX can't happen */ + if (fi == NULL) { goto exit; } fi->apath = filenames.data; /* Ick */ diff --git a/lib/rpmte.c b/lib/rpmte.c index 7039b30d0..d1e4f8778 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -676,6 +676,7 @@ static Header rpmteFDHeader(rpmte te) static int rpmteOpen(rpmte te, int reload_fi) { + int rc = 0; /* assume failure */ Header h = NULL; if (te == NULL || te->ts == NULL || rpmteFailed(te)) goto exit; @@ -694,13 +695,16 @@ static int rpmteOpen(rpmte te, int reload_fi) if (reload_fi) { te->fi = getFI(te, h); } + + /* This can fail if we get a different, bad header from callback */ + rc = (te->fi != NULL); rpmteSetHeader(te, h); headerFree(h); } exit: - return (h != NULL); + return rc; } static int rpmteClose(rpmte te, int reset_fi) diff --git a/lib/transaction.c b/lib/transaction.c index 50dedb1cf..5101a1a6e 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -990,6 +990,7 @@ void checkInstalledFiles(rpmts ts, uint64_t fileCount, rpmFpHash ht, fingerPrint switch (rpmteType(p)) { case TR_ADDED: if (!otherFi) { + /* XXX What to do if this fails? */ otherFi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); } rpmfiSetFX(fi, recs[j].fileno); diff --git a/lib/verify.c b/lib/verify.c index 21289d163..35612fe4b 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -339,6 +339,9 @@ static int verifyHeader(rpmts ts, Header h, rpmVerifyAttrs omitMask, int ghosts) int ec = 0; /* assume no problems */ rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_FLAGS_VERIFY); + if (fi == NULL) + return 1; + rpmfiInit(fi, 0); while (rpmfiNext(fi) >= 0) { rpmfileAttrs fileAttrs = rpmfiFFlags(fi); diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c index 4bfcc81e2..458e721b7 100644 --- a/python/rpmfi-py.c +++ b/python/rpmfi-py.c @@ -307,6 +307,11 @@ static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kw fi = rpmfiNew(NULL, h, tagN, flags); + if (fi == NULL) { + PyErr_SetString(PyExc_ValueError, "invalid file data in header"); + return NULL; + } + return rpmfi_Wrap(subtype, fi); } |