Skip to content

Commit

Permalink
Fix signature reserved space not restored on --delsign (rpm-software-…
Browse files Browse the repository at this point in the history
…management#2382)

Fixes a regression from commit 5c279fb
simplifying this a bit too much, and failing to restore the reclaimed
reserved signature space on after --delsign. Add a test-case to ensure
--addsign + --delsign returns the package to its original state
bit-by-bit.

Fixes: rpm-software-management#2382
  • Loading branch information
pmatilai committed Mar 7, 2023
1 parent 6b59cd8 commit be950ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sign/rpmgensig.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,20 @@ static int rpmSign(const char *rpm, int deleting, int flags)
res = -1;
}

/* Try to make new signature smaller to have size of original signature */
/* Adjust reserved size for added/removed signatures */
if (headerGet(sigh, RPMSIGTAG_RESERVEDSPACE, &utd, HEADERGET_MINMEM)) {
int diff = headerSizeof(sigh, HEADER_MAGIC_YES) - origSigSize;

if (diff > 0 && diff < utd.count) {
/* diff can be zero if nothing was added or removed */
if (diff) {
utd.count -= diff;
headerMod(sigh, &utd);
insSig = 1;
if (utd.count > 0 && utd.count < origSigSize) {
char *zeros = xcalloc(utd.count, sizeof(*zeros));
utd.data = zeros;
headerMod(sigh, &utd);
insSig = 1;
free(zeros);
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,25 @@ POST-DELSIGN
],
[])

# test --delsign restores the old package bit-per-bit
AT_CHECK([
RPMDB_INIT

ORIG="${RPMTEST}/data/RPMS/hello-2.0-1.x86_64.rpm"
NEW="${RPMTEST}/tmp/hello-2.0-1.x86_64.rpm"

cp ${ORIG} "${RPMTEST}"/tmp/
run rpmsign --key-id 1964C5FC --addsign ${NEW} > /dev/null
cmp -s ${ORIG} ${NEW}; echo $?
run rpmsign --delsign ${NEW} > /dev/null
cmp -s ${ORIG} ${NEW}; echo $?
],
[ignore],
[1
0
],
[])

# rpmsign --addsign <signed>
AT_CHECK([
RPMDB_INIT
Expand Down

0 comments on commit be950ea

Please sign in to comment.