diff options
| author | tb <> | 2026-05-18 04:24:01 +0000 |
|---|---|---|
| committer | tb <> | 2026-05-18 04:24:01 +0000 |
| commit | 8bb94b7a3d27460eb52d28debd9344cbb83a1108 (patch) | |
| tree | 5677e09bbaf5eed377dc7674763218788c21dd75 | |
| parent | 4aaf2a3333ff91e8329e1dddd19d905b9c523c02 (diff) | |
| download | openbsd-8bb94b7a3d27460eb52d28debd9344cbb83a1108.tar.gz openbsd-8bb94b7a3d27460eb52d28debd9344cbb83a1108.tar.bz2 openbsd-8bb94b7a3d27460eb52d28debd9344cbb83a1108.zip | |
x509_addr: do not call memcmp() on NULL
If the minimum length is 0, either a->data or b->data could be NULL, so
do not call memcmp() and let the length comparison decide. Doing it this
way preserves the RFC 3779, section 2.2.3.3 semantics and avoids the UB.
A valid IPAddressFamily has an addressFamily element of 2 or 3 octets:
2 octets for the AFI and 1 octet for the optional SAFI. The check as
it is written compares the AFIs and, if they're equal, lets absent SAFI
be smaller than any other SAFI. So IPv4 (0x0001) sorts before IPv4
unicast (0x000101) and that in turn sorts before IPv6 (0x0002).
Found by beck while breaking OpenSSL
ok kenjiro
| -rw-r--r-- | src/lib/libcrypto/x509/x509_addr.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c index ef2f7e0889..c48a0ab118 100644 --- a/src/lib/libcrypto/x509/x509_addr.c +++ b/src/lib/libcrypto/x509/x509_addr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: x509_addr.c,v 1.95 2026/04/26 17:58:58 tb Exp $ */ | 1 | /* $OpenBSD: x509_addr.c,v 1.96 2026/05/18 04:24:01 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Contributed to the OpenSSL Project by the American Registry for | 3 | * Contributed to the OpenSSL Project by the American Registry for |
| 4 | * Internet Numbers ("ARIN"). | 4 | * Internet Numbers ("ARIN"). |
| @@ -504,10 +504,10 @@ IPAddressFamily_cmp(const IPAddressFamily *const *a_, | |||
| 504 | const ASN1_OCTET_STRING *b = (*b_)->addressFamily; | 504 | const ASN1_OCTET_STRING *b = (*b_)->addressFamily; |
| 505 | int len, cmp; | 505 | int len, cmp; |
| 506 | 506 | ||
| 507 | len = MINIMUM(a->length, b->length); | 507 | if ((len = MINIMUM(a->length, b->length)) != 0) { |
| 508 | 508 | if ((cmp = memcmp(a->data, b->data, len)) != 0) | |
| 509 | if ((cmp = memcmp(a->data, b->data, len)) != 0) | 509 | return cmp; |
| 510 | return cmp; | 510 | } |
| 511 | 511 | ||
| 512 | return a->length - b->length; | 512 | return a->length - b->length; |
| 513 | } | 513 | } |
