Commit c5bd80d753 for openssl.org
commit c5bd80d753f0c89ca1fc8f8e66d19f75266fed03
Author: Bob Beck <beck@openssl.org>
Date: Sat Sep 5 11:26:17 2026 -0600
Mark the encoding stale in X509_set_serialNumber()
X509_set_serialNumber() returned straight from ASN1_STRING_copy()
without setting cert_info.enc.modified, so a certificate whose serial
number was replaced kept its old cached encoding and was still treated
as unmodified.
Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Thu Sep 17 16:44:27 2026
Merged-from: https://github.com/openssl/openssl/pull/32686
diff --git a/crypto/x509/x509_set.c b/crypto/x509/x509_set.c
index 11439bcafb..8b36ea6bd7 100644
--- a/crypto/x509/x509_set.c
+++ b/crypto/x509/x509_set.c
@@ -49,8 +49,8 @@ int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
if (x == NULL)
return 0;
in = &x->cert_info.serialNumber;
- if (in != serial)
- return ASN1_STRING_copy(in, serial);
+ if (in != serial && !ASN1_STRING_copy(in, serial))
+ return 0;
x->cert_info.enc.modified = 1;
return 1;
}