x509-cert: parse the empty string as the empty Name - #2444
Open
yuxi-liu-wired wants to merge 1 commit into
Open
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
RFC 4514 Section 2.1: "If the RDNSequence is an empty sequence, the
result is the empty or zero-length string", and `Display` does produce
"" for `Name::default()`. Section 3's grammar makes the RDN list
optional (`distinguishedName = [ relativeDistinguishedName ... ]`).
But `RdnSequence::from_str("")` split the empty string into one empty
RDN and failed, so the empty name could not be read back from its own
text form.
Return the empty sequence for "". A missing RDN between separators
(",", "CN=a,") is still an error.
Found by fuzzing the RFC 4514 Display -> FromStr round trip.
This branch has not been deployed
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.
RFC 4514 Section 2.1 says: "If the RDNSequence is an empty sequence, the result is the empty or zero-length string".
Displaydoes that:Name::default().to_string()is"". Section 3's grammar makes the list of RDNs optional (distinguishedName = [ relativeDistinguishedName *( COMMA relativeDistinguishedName ) ]).RdnSequence::from_str("")split the empty string into one empty RDN and returned an error, so the empty name couldn't be read back from its own text form:Empty subject names are normal in X.509: RFC 5280 4.1.2.6 allows an empty subject when subjectAltName is present.
Fix:
RdnSequence::from_strreturns the empty sequence for"". A missing RDN between separators (",","CN=a,") is still an error.from_str_empty_nameintests/name.rsfails on master and passes with this change. The x509-cert CI steps (--no-default-features, default,--features arbitrary/hazmat/sct, the feature powerset,--all-featuresin debug and release, on stable and 1.85),cargo fmt --checkandcargo +1.90.0 clippy --all-features --testsall pass.Found by fuzzing the RFC 4514
Display→FromStrround trip. This PR was produced by AI agents (Claude), from the fuzzing and the fix through to this description.