diff options
| author | Bob Beck <[email protected]> | 2026-09-14 17:56:07 +0200 |
|---|---|---|
| committer | Tomas Mraz <[email protected]> | 2026-09-18 11:05:47 +0200 |
| commit | 5df7d33922d8a18e77bee28aeadbe2628fc34a7b (patch) | |
| tree | 85b14d16b19b0bb8718866a7a7fb90a9616e0360 /include | |
| parent | Fix potential DoS and undefined behavior in KRB5KDF due to zero-length constant (diff) | |
| download | openssl-5df7d33922d8a18e77bee28aeadbe2628fc34a7b.tar.gz openssl-5df7d33922d8a18e77bee28aeadbe2628fc34a7b.zip | |
NUL-terminate ASN1_STRING data built inside libcrypto
Add ossl_asn1_string_set1_data() and ossl_asn1_string_set1_string(),
copies of the public setters that also write a NUL byte after the data,
and switch all libcrypto callers to them. The ecosystem still treats
ASN1_STRING data as C strings; this keeps it working while it is fixed.
Removing the terminator later is a one-argument change in one function.
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Andrew Dinh <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
Merge-date: Fri Sep 18 09:05:58 2026
Merged-from: https://github.com/openssl/openssl/pull/32829
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/asn1.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/crypto/asn1.h b/include/crypto/asn1.h index 7000d7d33d4..ef5b836313f 100644 --- a/include/crypto/asn1.h +++ b/include/crypto/asn1.h @@ -181,6 +181,28 @@ X509_ALGOR *ossl_X509_ALGOR_from_nid(int nid, int ptype, void *pval); void ossl_asn1_bit_string_clear_unused_bits(ASN1_STRING *str); void ossl_asn1_bit_string_set_unused_bits(ASN1_STRING *str, unsigned int num); +/** + * @brief Set str's data as ASN1_STRING_set1_data() does, and NUL-terminate it. + * The terminator is not counted in str->length. + * @param str the string to set + * @param data the bytes to copy, or NULL to allocate len bytes unset + * @param len the number of bytes at data + * @returns 1 on success, 0 on failure + * @see ASN1_STRING_set1_data(3) + */ +int ossl_asn1_string_set1_data(ASN1_STRING *str, const uint8_t *data, + size_t len); + +/** + * @brief Set str's data as ASN1_STRING_set1_string() does, and NUL-terminate it. + * The terminator is not counted in str->length. + * @param str the string to set + * @param c_string the NUL-terminated string to copy + * @returns 1 on success, 0 on failure + * @see ASN1_STRING_set1_string(3) + */ +int ossl_asn1_string_set1_string(ASN1_STRING *str, const char *c_string); + int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx, int depth, |
