peass-ng/PEASS-ng · error · ArgumentNullException
str
Error message
str
What it means
This obsolete byte-array constructor of DerBmpString throws ArgumentNullException when the caller passes a null byte array; it fires at the very first guard of the constructor before any encoding length checks, meaning the code constructed a BMP string from a null buffer.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBmpString.cs:61
{
Asn1Object o = obj.GetObject();
if (isExplicit || o is DerBmpString)
{
return GetInstance(o);
}
return new DerBmpString(Asn1OctetString.GetInstance(o).GetOctets());
}
/**
* basic constructor - byte encoded string.
*/
[Obsolete("Will become internal")]
public DerBmpString(byte[] str)
{
if (str == null)
throw new ArgumentNullException("str");
int byteLen = str.Length;
if (0 != (byteLen & 1))
throw new ArgumentException("malformed BMPString encoding encountered", "str");
int charLen = byteLen / 2;
char[] cs = new char[charLen];
for (int i = 0; i != charLen; i++)
{
cs[i] = (char)((str[2 * i] << 8) | (str[2 * i + 1] & 0xff));
}
this.str = new string(cs);
}
internal DerBmpString(char[] str)
{View on GitHub (pinned to 53fb989abc)
Solutions
- Pass a non-null byte[]; use Array.Empty<byte>() if there is genuinely no content.
- Construct from a string instead: new DerBmpString("text") handles encoding for you.
- Fix the upstream producer that returned null and handle its failure case.
Example fix
// before var bmp = new DerBmpString(GetEncodedName()); // may return null // after byte[] enc = GetEncodedName() ?? Array.Empty<byte>(); var bmp = new DerBmpString(enc);
Defensive patterns
Strategy: validation
Validate before calling
if (str == null) throw new InvalidOperationException("BMPString byte content missing"); Type guard
static bool HasBmpBytes(byte[] b) => b != null;
Prevention
- Prefer the public string constructor over raw byte[]
- Null-coalesce byte producers before constructing ASN.1 objects
- Handle decode failures at the source instead of propagating null
When it happens
Trigger: Calling new DerBmpString((byte[])null) — e.g. passing the result of a failed encode or a null field extracted from a structure.
Common situations: Bridge code converting strings to bytes where the string was null; decoding pipelines that propagate null instead of empty arrays.
Related errors
- data
- must be in the range 0 to 7
- if 'data' is empty, 'padBits' must be 0
- attempt to get non-octet aligned data from BIT STRING
- truncated BIT STRING detected
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/2eda17a3994fb03e.
Report an issue: GitHub.