summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDemi Marie Obenour <demi@invisiblethingslab.com>2022-03-16 22:11:34 -0400
committerMichal Domonkos <mdomonko@redhat.com>2022-07-01 10:52:14 +0200
commit6a8969d3ebbe74bea17dff9b22a7beb00008ad6a (patch)
treec79e346618419a1345517286ce0a2ac696423eaf
parent9e9745e25fc1899bb8da21b08e583b2bd8cce355 (diff)
downloadrpm-6a8969d3ebbe74bea17dff9b22a7beb00008ad6a.tar.gz
Fix the OpenPGP parser tests
I forgot to wire it up to the test suite in ad97e2fceaae3a853d9332324156630677384989, and they did not test all of the cases they were supposed to. This checks that valid old- and new-format signature packets with correct lengths are accepted, and that incorrect lengths are rejected. Backported from commit ba0fe1be9a6093f0a49921f38e2e8826dc825340
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/rpmpgpcheck.c33
-rw-r--r--tests/rpmtests.at1
3 files changed, 31 insertions, 9 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c7bfaf7b8..a1e961678 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,6 +10,10 @@ CLEANFILES =
TESTSUITE = $(srcdir)/rpmtests
EXTRA_DIST += local.at $(TESTSUITE)
+AM_CPPFLAGS = -I$(top_builddir)/include
+
+rpmpgpcheck_LDADD = ../rpmio/librpmio.la
+
## testsuite components
TESTSUITE_AT = rpmtests.at
TESTSUITE_AT += rpmgeneral.at
@@ -131,6 +135,8 @@ EXTRA_DIST += data/misc/libhello.so
.PHONY: populate_testing
+check_PROGRAMS = rpmpgpcheck
+
# testsuite voodoo
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): $(srcdir)/package.m4 local.at $(TESTSUITE_AT)
diff --git a/tests/rpmpgpcheck.c b/tests/rpmpgpcheck.c
index 16c5f99c6..baae2a10f 100644
--- a/tests/rpmpgpcheck.c
+++ b/tests/rpmpgpcheck.c
@@ -1,5 +1,4 @@
#include <stddef.h>
-#include <assert.h>
#include <limits.h>
#include <stdio.h>
@@ -25,28 +24,44 @@ static long data_eddsa_asc_len = 119;
int main(void)
{
long s = sysconf(_SC_PAGE_SIZE);
- assert(s > data_eddsa_asc_len && s < LONG_MAX / 2);
+ if (!(s > data_eddsa_asc_len && s < LONG_MAX / 2))
+ return 1;
- void *addr = mmap(NULL, 2 * s, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ uint8_t *addr = mmap(NULL, 2 * s, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
return 1;
}
- if (mprotect((unsigned char *)addr + s, (size_t)s, PROT_NONE)) {
+ if (mprotect(addr + s, (size_t)s, PROT_NONE)) {
perror("mprotect");
return 1;
}
- memcpy((unsigned char *)addr + (s - data_eddsa_asc_len), data_eddsa_asc, data_eddsa_asc_len);
+ memcpy(addr + (s - data_eddsa_asc_len), data_eddsa_asc, data_eddsa_asc_len);
pgpDigParams params = NULL;
addr += s - data_eddsa_asc_len;
if (pgpPrtParams(addr, data_eddsa_asc_len, PGPTAG_SIGNATURE, &params)) {
- fprintf(stderr, "Valid signature not properly accepted\n");
+ fprintf(stderr, "Valid old-format signature not properly accepted\n");
+ return 1;
+ }
+ params = pgpDigParamsFree(params);
+ addr[0] = 0xC2;
+ if (pgpPrtParams(addr, data_eddsa_asc_len, PGPTAG_SIGNATURE, &params)) {
+ fprintf(stderr, "Valid new-format signature not properly accepted\n");
+ return 1;
+ }
+ params = pgpDigParamsFree(params);
+ addr[0] = 0x88;
+ addr[1] += 5;
+ if (pgpPrtParams(addr, data_eddsa_asc_len, 0, &params) != -1) {
+ fprintf(stderr, "Invalid old-format signature packet not properly rejected\n");
return 1;
}
- data_eddsa_asc[1] += 1;
- if (pgpPrtParams(addr, data_eddsa_asc_len, PGPTAG_SIGNATURE, &params) != -1) {
- fprintf(stderr, "Invalid signature not properly rejected\n");
+ params = pgpDigParamsFree(params);
+ addr[0] = 0xC2;
+ if (pgpPrtParams(addr, data_eddsa_asc_len, 0, &params) != -1) {
+ fprintf(stderr, "Invalid new-format signature packet not properly rejected\n");
return 1;
}
+ params = pgpDigParamsFree(params);
return 0;
}
diff --git a/tests/rpmtests.at b/tests/rpmtests.at
index 153c796f2..0f22667ee 100644
--- a/tests/rpmtests.at
+++ b/tests/rpmtests.at
@@ -1,3 +1,4 @@
+m4_include([rpmpgp.at])
m4_include([rpmgeneral.at])
m4_include([rpmvercmp.at])
m4_include([rpmmacro.at])