Harden asn1 oid loader to invalid inputs
authorNeil Horman <nhorman@openssl.org>
Tue, 5 Dec 2023 20:24:20 +0000 (15:24 -0500)
committerTomas Mraz <tomas@openssl.org>
Fri, 15 Dec 2023 11:40:38 +0000 (12:40 +0100)
commit703e85642471fcd16ce083fdf3b4e81e9be148cb
tree7871af64dd0fabefb696e9475a78af29c098c56b
parent45d80b47231984b9c9240438bd0325d614734ca3
Harden asn1 oid loader to invalid inputs

In the event that a config file contains this sequence:
=======
openssl_conf = openssl_init

config_diagnostics = 1

[openssl_init]
oid_section = oids

[oids]
testoid1 = 1.2.3.4.1
testoid2 = A Very Long OID Name, 1.2.3.4.2
testoid3 = ,1.2.3.4.3
======

The leading comma in testoid3 can cause a heap buffer overflow, as the
parsing code will move the string pointer back 1 character, thereby
pointing to an invalid memory space

correct the parser to detect this condition and handle it by treating it
as if the comma doesn't exist (i.e. an empty long oid name)

(cherry picked from commit a552c23c6502592c1b3c67d93dd7e5ffbe958aa4)

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23034)

(cherry picked from commit d802bfbf80bab00123a4a6209f255852b3a10207)
crypto/asn1/asn_moid.c
test/recipes/04-test_asn1_parse.t [new file with mode: 0644]
test/test_asn1_parse.cnf [new file with mode: 0644]