summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2016-11-15 13:48:36 +0200
committerPanu Matilainen <pmatilai@redhat.com>2016-11-15 14:01:34 +0200
commitffeed045ad0a022b55215b9ec040fc0471826a60 (patch)
tree47108ca3c965963d641ab3a1f11ca483cd9bf3ed
parentd022809023b843e680ae891938f0f4da9ba6fafa (diff)
downloadrpm-ffeed045ad0a022b55215b9ec040fc0471826a60.tar.gz
Add error message retval argument to headerVerifyInfo()
Collapses four copy-paste variants of the theme into one. But, wait - this loses "sigh " prefix on signature header errors! Oh, the tragedy!
-rw-r--r--lib/header.c7
-rw-r--r--lib/header_internal.h3
-rw-r--r--lib/package.c19
-rw-r--r--lib/signature.c7
4 files changed, 12 insertions, 24 deletions
diff --git a/lib/header.c b/lib/header.c
index 653925e99..73b5217fb 100644
--- a/lib/header.c
+++ b/lib/header.c
@@ -204,7 +204,7 @@ Header headerNew(void)
}
int headerVerifyInfo(int il, int dl, const struct entryInfo_s * pe,
- struct entryInfo_s * info)
+ struct entryInfo_s * info, char **emsg)
{
int i, tsize;
int32_t end = 0;
@@ -234,6 +234,11 @@ int headerVerifyInfo(int il, int dl, const struct entryInfo_s * pe,
i = -1; /* Everything ok */
err:
+ if (i >= 0 && emsg) {
+ rasprintf(emsg, _("tag[%d]: BAD, tag %d type %d offset %d count %d"),
+ i, info->tag, info->type, info->offset, info->count);
+ }
+
return i;
}
diff --git a/lib/header_internal.h b/lib/header_internal.h
index 1e9676e6c..d9edd69bf 100644
--- a/lib/header_internal.h
+++ b/lib/header_internal.h
@@ -76,11 +76,12 @@ rpmRC headerVerifyRegion(rpmTagVal regionTag,
* @param dl no. of bytes in header data.
* @param pe 1st element in tag array, big-endian
* @retval info failing (or last) tag element, host-endian
+ * @retvar emsg possible error message (malloced) or NULL to disable
* @return -1 on success, otherwise failing tag element index
*/
RPM_GNUC_INTERNAL
int headerVerifyInfo(int il, int dl, const struct entryInfo_s * pe,
- struct entryInfo_s * info);
+ struct entryInfo_s * info, char **emsg);
/** \ingroup header
diff --git a/lib/package.c b/lib/package.c
index db1b13e7c..11cac96a8 100644
--- a/lib/package.c
+++ b/lib/package.c
@@ -179,13 +179,8 @@ static rpmRC headerSigVerify(rpmKeyring keyring, rpmVSFlags vsflags,
/* Find a header-only digest/signature tag. */
for (int i = ril; i < il; i++) {
- if (headerVerifyInfo(1, dl, pe+i, &einfo) != -1) {
- rasprintf(buf,
- _("tag[%d]: BAD, tag %d type %d offset %d count %d"),
- i, einfo.tag, einfo.type,
- einfo.offset, einfo.count);
+ if (headerVerifyInfo(1, dl, pe+i, &einfo, buf) != -1)
goto exit;
- }
switch (einfo.tag) {
case RPMTAG_SHA1HEADER: {
@@ -277,11 +272,8 @@ rpmRC headerVerifyRegion(rpmTagVal regionTag,
}
/* Check (and convert) the 1st tag element. */
- if (headerVerifyInfo(1, dl, pe, &einfo) != -1) {
- rasprintf(buf, _("tag[%d]: BAD, tag %d type %d offset %d count %d"),
- 0, einfo.tag, einfo.type, einfo.offset, einfo.count);
+ if (headerVerifyInfo(1, dl, pe, &einfo, buf) != -1)
goto exit;
- }
/* Is there an immutable header region tag? */
if (!(einfo.tag == regionTag)) {
@@ -380,13 +372,8 @@ static rpmRC headerVerify(rpmKeyring keyring, rpmVSFlags vsflags,
/* Sanity check the rest of the header structure. */
if (rc != RPMRC_FAIL) {
struct entryInfo_s info;
- int xx = headerVerifyInfo(ril-1, dl, pe+1, &info);
- if (xx != -1) {
- rasprintf(&buf,
- _("tag[%d]: BAD, tag %d type %d offset %d count %d"),
- xx+1, info.tag, info.type, info.offset, info.count);
+ if (headerVerifyInfo(ril-1, dl, pe+1, &info, &buf) != -1)
rc = RPMRC_FAIL;
- }
}
/* Verify header-only digest/signature if there is one we can use. */
diff --git a/lib/signature.c b/lib/signature.c
index ea8d80ce6..95d3be576 100644
--- a/lib/signature.c
+++ b/lib/signature.c
@@ -197,13 +197,8 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, char ** msg)
/* Sanity check signature tags */
for (i = 1; i < il; i++) {
struct entryInfo_s info;
- xx = headerVerifyInfo(1, dl, pe+i, &info);
- if (xx != -1) {
- rasprintf(&buf,
- _("sigh tag[%d]: BAD, tag %d type %d offset %d count %d"),
- i, info.tag, info.type, info.offset, info.count);
+ if (headerVerifyInfo(1, dl, pe+i, &info, &buf) != -1)
goto exit;
- }
}
/* OK, blob looks sane, load the header. */