{"record":{"id":"046d2211d1b74c47","repo":"peass-ng/PEASS-ng","slug":"data","errorCode":null,"errorMessage":"data","messagePattern":"data","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs","lineNumber":77,"sourceCode":"\n            if (isExplicit || o is DerBitString)\n            {\n                return GetInstance(o);\n            }\n\n            return FromAsn1Octets(((Asn1OctetString)o).GetOctets());\n        }\n\n        /**\n\t\t * @param data the octets making up the bit string.\n\t\t * @param padBits the number of extra bits at the end of the string.\n\t\t */\n        public DerBitString(\n            byte[] data,\n            int padBits)\n        {\n            if (data == null)\n                throw new ArgumentNullException(\"data\");\n            if (padBits < 0 || padBits > 7)\n                throw new ArgumentException(\"must be in the range 0 to 7\", \"padBits\");\n            if (data.Length == 0 && padBits != 0)\n                throw new ArgumentException(\"if 'data' is empty, 'padBits' must be 0\");\n\n            this.mData = Arrays.Clone(data);\n            this.mPadBits = padBits;\n        }\n\n        public DerBitString(\n            byte[] data)\n            : this(data, 0)\n        {\n        }\n\n        public DerBitString(\n            int namedBits)\n        {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerBitString.cs#L59-L95","documentation":"DerBitString's constructor validates its inputs and throws ArgumentNullException when the data byte array is null. BouncyCastle ASN.1 types are immutable value objects, so a null payload is never acceptable; the library fails fast at construction rather than producing a corrupt encoded BIT STRING.","triggerScenarios":"Calling new DerBitString(null, padBits) (or passing a null byte[] from a helper that failed to load key/certificate material) directly to the DerBitString(byte[], int) constructor.","commonSituations":"Parsing X.509 keys or certificates where a preceding decode step silently returned null; refactoring code that used to pass a populated buffer but now passes an uninitialized array.","solutions":["Ensure the byte[] passed to DerBitString is non-null before constructing; initialize or load it first.","Check the upstream call that produced the array (file read, decode, P/Invoke) and handle its null/failure return.","If null legitimately means 'no value', skip creating the DerBitString instead of constructing one."],"exampleFix":"// before\nvar bs = new DerBitString(GetRawBits(), 0); // GetRawBits() may return null\n// after\nbyte[] raw = GetRawBits();\nif (raw == null) throw new InvalidOperationException(\"no bit string material loaded\");\nvar bs = new DerBitString(raw, 0);","handlingStrategy":"try-catch","validationCode":"if (data == null) throw new InvalidOperationException(\"BIT STRING data not loaded\");","typeGuard":"static bool IsUsableBitStringData(byte[] d) => d != null;","tryCatchPattern":"try { var bs = new DerBitString(data, padBits); }\ncatch (ArgumentNullException) { /* data was null: fix loading path */ }","preventionTips":["Never pass nullable byte[] straight into ASN.1 constructors; null-coalesce or early-return","Assert non-null inputs in unit tests for encode helpers","Let the library encode from strings/objects instead of raw byte arrays when possible"],"tags":["csharp","asn1","null-argument","bouncycastle"],"backgroundTag":"null-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}