From 3064ce6bfa8669f86c58ed74fb3f737671ec7fb1 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 28 May 2022 01:26:32 +0800 Subject: Bugfix: buggy pkcs7 unpad implementation. SEGV when n=1. --- main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.c b/main.c index 97dac06..37f5a0a 100644 --- a/main.c +++ b/main.c @@ -117,6 +117,10 @@ bool yield_possible_key( * the data is not padded with valid pkcs7 */ int pkcs7_check_pad(const char *buf, size_t n) { if (!n) return -1; + if (n == 1) { + /* if total length is 1, the only valid string is 0x1 */ + return (buf[0] == 1u) ? 1 : -1; + } --n; unsigned char pad = buf[n--]; if (!pad) return -1; -- cgit v1.2.3