The attached file oid_oob_small.crt causes a reproducible crash on my computer (x86_64,Linux,Glibc 2.21):
~/libksba-1.3.3$ ./tests/cert-basic oid_oob_small.crt
...
AuthorityKeyIdentifier: 1.2.840.113549.1.9.1=#696E73656375726540746573742E696E736563757265,CN=For Tests
Only,O=InsecureTestCertificate,C=de
serial: (#00#) keyIdentifier: (#BF53438278D09EC380E51B67CA0500DFB94883A5#)
KeyUsage: digitalSignature keyEncipherment keyAgreement
this is not going to end well: length=2819585
Segmentation fault
The program has been instrumented with the following change at the entry of the function ksba_oid_to_str():
diff -ru orig/libksba-1.3.3/src/oid.c libksba-1.3.3/src/oid.c
- orig/libksba-1.3.3/src/oid.c 2014-11-25 12:42:56.000000000 +0100
+++ libksba-1.3.3/src/oid.c 2016-05-01 12:41:55.565772704 +0200
@@ -66,7 +66,7 @@
char *string, *p; int n = 0; unsigned long val, valmask;
+ if (length>1000000) printf("this is not going to end well: length=%zu\n", length);
valmask = (unsigned long)0xfe << (8 * (sizeof (valmask) - 1)); /* To calculate the length of the string we can safely assume an
After submitting this entry, I hope to be able to attach another file showing that the value of “length” can be even
larger than 2819585. The bug submission form only allows one file to be attached.
The call stack at the point of the ouf-of-bounds read is:
src/oid.c:105:[kernel] warning: out of bounds read. assert \valid_read(buf+n);
stack: _ksba_oid_to_str :: src/cert.c:1462 <- _ksba_cert_get_ext_key_usages :: src/visibility.c:259 <- ksba_cert_get_ext_key_usages :: tests/cert-basic.c:265 <- list_extensions :: tests/cert-basic.c:545 <- one_file :: tests/cert-basic.c:592 <- main
The title refers to ksba_cert_get_ext_key_usages() as culprit because as the additional printf() call shows,
ksba_oid_to_str() is passed incoherent arguments and is not at fault.