Visitar URL original
pem: reject indefinite-length DER in `pem_read_asn1_length()` by abdul-khaliq-khalid · Pull Request #2702 · libssh2/libssh2 · GitHub
Skip to content

pem: reject indefinite-length DER in pem_read_asn1_length() - #2702

Open
abdul-khaliq-khalid wants to merge 2 commits into
libssh2:masterfrom
abdul-khaliq-khalid:pem-asn1-indefinite-length
Open

abdul-khaliq-khalid wants to merge 2 commits into
libssh2:masterfrom
abdul-khaliq-khalid:pem-asn1-indefinite-length

Conversation

@abdul-khaliq-khalid

Copy link
Copy Markdown
Contributor

pem_read_asn1_length() in src/pem.c takes a 0x80 length octet as the long form with zero length bytes, so the 1 + lenlen > datalen guard from #2028 passes with lenlen 0 and the next line still reads data[1], one byte past the element, and uses it as the length. On the libgcrypt backend a PEM RSA or DSA private key whose DER body is just 30 80 reaches it through libssh2_userauth_publickey_fromfile() or frommemory(), and whether the SEQUENCE is accepted depends on whatever byte happens to follow the span (AddressSanitizer reports a one byte heap-buffer-overflow read on an exactly sized buffer). 0x80 is the DER indefinite form, which never appears in a valid key, so reject it before touching the length bytes; I checked #2028 and #2011 first and this is the one long-form case that fix leaves open. The new test in tests/test_simple.c fails on master and passes with this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants