summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-05-28 01:26:32 +0800
committerKeuin <[email protected]>2022-05-28 01:26:32 +0800
commit3064ce6bfa8669f86c58ed74fb3f737671ec7fb1 (patch)
treec5576cfa4d5965f2229f9be7f579fc9b04edc6ed
parent15305a1351d9f7eb36b444ebd693f78a38600af0 (diff)
Bugfix: buggy pkcs7 unpad implementation. SEGV when n=1.
-rw-r--r--main.c4
1 files changed, 4 insertions, 0 deletions
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;