summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2023-02-22 09:31:06 +0200
committerMichal Domonkos <mdomonko@redhat.com>2023-03-13 15:32:25 +0100
commit1e01be65ddd534d595f7397ee604fa51e32130b4 (patch)
treeaab090e46ba96742e85e7e4f9a1ee0025bff4b90
parenta94e971dbb10e8bc929108a65c7bb1d5b1d9e77e (diff)
downloadrpm-1e01be65ddd534d595f7397ee604fa51e32130b4.tar.gz
Copy original lead on signing instead of recreating
Fixes a regression from commit 3255273ae0fabd03c9738249a29c9c1e15f28f64 where the arch and os fields of the lead may change depending on the package arch and the host where --addsign/--delsign is executed. This is hard to test for specifically as the test-suite can run on any architecture, but the bit-per-bit comparison test added in the previous commit will catch differences here too. Fixes: #1326 (cherry picked from commit 0c02e4899e72eae8ccb484fbb22c04f12fae2f0d)
-rw-r--r--sign/rpmgensig.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c
index 33a48f8f0..37898ed8a 100644
--- a/sign/rpmgensig.c
+++ b/sign/rpmgensig.c
@@ -661,14 +661,14 @@ static int rpmSign(const char *rpm, int deleting, int flags)
if (sigh == NULL) /* XXX can't happen */
goto exit;
+ if (Fseek(fd, insSig ? sigStart : 0, SEEK_SET) < 0) {
+ rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"),
+ rpm, Fstrerror(fd));
+ goto exit;
+ }
+
if (insSig) {
/* Insert new signature into original rpm */
- if (Fseek(fd, sigStart, SEEK_SET) < 0) {
- rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"),
- rpm, Fstrerror(fd));
- goto exit;
- }
-
if (rpmWriteSignature(fd, sigh)) {
rpmlog(RPMLOG_ERR, _("%s: rpmWriteSignature failed: %s\n"), rpm,
Fstrerror(fd));
@@ -676,6 +676,7 @@ static int rpmSign(const char *rpm, int deleting, int flags)
}
res = 0;
} else {
+ char lbuf[RPMLEAD_SIZE];
/* Replace orignal rpm with new rpm containing new signature */
rasprintf(&trpm, "%s.XXXXXX", rpm);
ofd = rpmMkTemp(trpm);
@@ -684,11 +685,12 @@ static int rpmSign(const char *rpm, int deleting, int flags)
goto exit;
}
- /* Write the lead/signature of the output rpm */
- rc = rpmLeadWrite(ofd, h);
- if (rc != RPMRC_OK) {
- rpmlog(RPMLOG_ERR, _("%s: writeLead failed: %s\n"), trpm,
- Fstrerror(ofd));
+ /* Copy lead from original */
+ if (!(Fread(lbuf, 1, RPMLEAD_SIZE, fd) == RPMLEAD_SIZE &&
+ Fwrite(lbuf, 1, RPMLEAD_SIZE, ofd) == RPMLEAD_SIZE))
+ {
+ rpmlog(RPMLOG_ERR, _("%s: failed to copy rpm lead: %s\n"),
+ trpm, Fstrerror(ofd));
goto exit;
}