fix: OpenSSL 4.0 — use ASN1_STRING accessors instead of direct struct member access#61
Open
jonasbn wants to merge 8 commits into
Open
fix: OpenSSL 4.0 — use ASN1_STRING accessors instead of direct struct member access#61jonasbn wants to merge 8 commits into
jonasbn wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…compat Direct ->data and ->length member access on ASN1_BMPSTRING, ASN1_UTF8STRING, ASN1_OCTET_STRING, and ASN1_BIT_STRING fails to compile under OpenSSL 4.0, which made struct asn1_string_st opaque. Replace with ASN1_STRING_length() and ASN1_STRING_get0_data() throughout print_attribute(). A compat macro maps ASN1_STRING_get0_data to ASN1_STRING_data for OpenSSL < 1.1.0. Fixes: #60
…ribs Avoids BUF_MEM struct member dereference, which may become opaque in future OpenSSL releases. BIO_get_mem_data() is the documented accessor for memory BIOs and works across all supported OpenSSL versions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the XS OpenSSL integration to be compatible with OpenSSL 4.0’s move to opaque ASN.1/BIO-related structs by switching from direct struct member access to documented accessor APIs.
Changes:
- Added a compatibility macro for
ASN1_STRING_get0_data()on OpenSSL < 1.1.0 so call sites can be unconditional. - Replaced
->data/->lengthaccesses inprint_attribute()withASN1_STRING_get0_data()andASN1_STRING_length(). - Replaced
BIO_get_mem_ptr()/BUF_MEMaccess withBIO_get_mem_data()inprint_attribs().
Comments suppressed due to low confidence (1)
PKCS12.xs:668
- In the BMPSTRING branch,
*attributeis resized tolengthbytes but then populated viastrncpy()without guaranteeing NUL-termination. The resulting buffer can be read withstrlen()later (e.g., when storing into the hash), which risks reading past the allocation. Allocatelength + 1and explicitly terminate.
if(*attribute != NULL) {
Renew(*attribute, length, char);
strncpy(*attribute, value, length);
} else {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+693
to
+694
| Renew(*attribute, (size_t)length * 4, char); | ||
| get_hex(*attribute, av->value.octet_string->data, length); | ||
| get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length); |
Comment on lines
+694
to
+696
| get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length); | ||
| } else { | ||
| hex_prin(out, av->value.octet_string->data, length); | ||
| hex_prin(out, (unsigned char *)ASN1_STRING_get0_data(av->value.octet_string), length); |
Comment on lines
+706
to
+707
| Renew(*attribute, (size_t)length * 4, char); | ||
| get_hex(*attribute, av->value.bit_string->data, length); | ||
| get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length); |
Comment on lines
+707
to
+709
| get_hex(*attribute, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length); | ||
| } else { | ||
| hex_prin(out, av->value.bit_string->data, length); | ||
| hex_prin(out, (unsigned char *)ASN1_STRING_get0_data(av->value.bit_string), length); |
Comment on lines
820
to
821
| if((hv_store(bag_hv, attr_key, (I32)attr_key_len, newSVpvn(attribute_value, strlen(attribute_value)), 0)) == NULL) | ||
| croak("unable to add MAC to the hash"); |
…ssages - Update get_hex() and hex_prin() signatures to accept const unsigned char *, eliminating the const-cast away from ASN1_STRING_get0_data() at call sites - Cast ASN1_STRING_get0_data() to const char * for BIO_printf %s format argument to silence -Wformat under -Wall -Werror - Fix misleading croak messages in hv_store attribute path: was "unable to add MAC to the hash", now "unable to store attribute in hash" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
struct asn1_string_st(backing type forASN1_BMPSTRING,ASN1_UTF8STRING,ASN1_OCTET_STRING,ASN1_BIT_STRING) opaque, breaking direct->data/->lengthaccess inprint_attribute()— Debian bug #1138300, closes OpenSSL 4.0 compatibility: print_attribute uses direct ASN1_STRING struct member access #57, closes Build failure with OpenSSL 4.0 #60.ASN1_STRING_get0_datain the existing#if OPENSSL_VERSION_NUMBER < 0x10100000Lblock so the replacement is unconditional — no per-call#ifdefrequired.ASN1_STRING_length()andASN1_STRING_get0_data().BUF_MEM*/BIO_get_mem_ptr()pattern inprint_attribs()withBIO_get_mem_data(), the documented accessor that avoids opaque struct access.X509_ATTRIBUTE_get0_object()andX509_ATTRIBUTE_get0_type()return values (OpenSSL 4.0 tightened these to returnconstpointers).Commits
compat: add ASN1_STRING_get0_data macro for OpenSSL < 1.1.0fix: use ASN1_STRING accessor API in print_attribute for OpenSSL 4.0 compatfix: replace BUF_MEM direct access with BIO_get_mem_data in print_attribsstyle: cast BIO_set_close return to void for consistencyfix: use CONST_ASN1_OBJECT and CONST_ASN1_TYPE for X509_ATTRIBUTE accessorsTest plan
prove -lr -l -b -I inc t)-Wall -WerrorviaAUTHOR_TESTING=1) / macOS / Windows (Strawberry Perl) matrix🤖 Generated with Claude Code