Files
Si Beaumont d930168b86 Merge commit from fork
When building the byte view of a subject alternative name, NIOSSL reads
the `ASN1_STRING` member of the BoringSSL `GENERAL_NAME` union for every
entry without checking the name's type. The union only holds an
`ASN1_STRING` for the string-shaped GeneralName types (`dNSName`,
`rfc822Name`, `uniformResourceIdentifier`, `iPAddress`). For the other
types (`otherName`, `x400Address`, `directoryName`, `ediPartyName`,
`registeredID`) the union holds a different structure, so this reads the
buffer's base pointer and length out of unrelated memory.

The SAN list is parsed from an X.509 certificate, which is untrusted in
the usual TLS/mTLS case, and `contents` is reachable through the public,
albeit underscored, `_subjectAlternativeNames()` API.

NIOSSL should only interpret the union as an `ASN1_STRING` for the
string-shaped types and expose empty contents for the rest.

- In `_SubjectAlternativeNames.Storage.subscript`, switch on the GeneralName
  type. Build the `ASN1_STRING`-backed byte buffer only for `dNSName`,
  `rfc822Name`, `uniformResourceIdentifier` and `iPAddress`; expose an empty
  buffer for every other type.
- Add a test that parses a certificate carrying an `otherName` SAN followed by a
  `dNSName`, asserting the `otherName` has empty `contents` while the `dNSName`
  is read normally.

Reading the `contents` of a non-string subject alternative name no longer reads
out of bounds; it returns empty. String-typed names are unaffected. NIOSSL's
built-in identity verification already filters by name type, so the default
handshake path was not affected; this fixes the behaviour for callers of
`_subjectAlternativeNames()` that read `contents` for arbitrary name types.
2026-07-15 13:05:47 +01:00
..