NULL Pointer Dereference
A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL.
NULL pointer dereferences typically cause the application to crash. In some cases, they may be exploitable for denial of service or potentially for code execution.
इस भेद्यता को कैसे ठीक करें
Use the two-value form of type assertion or type switch to handle failures gracefully
- func processData(data interface{}) { - m := data.(map[string]interface{}) - fmt.Println(m["key"]) + func processData(data interface{}) error { + m, ok := data.(map[string]interface{}) + if !ok { + return errors.New("invalid data type") + } + fmt.Println(m["key"]) + return nil }
Replace non-null assertions (!) with explicit null checks or optional chaining
interface Config { database?: { host: string; port: number; }; } function connect(config: Config) { - const host = config.database!.host; - const port = config.database!.port; + if (!config.database) { + throw new Error('Database configuration is required'); + } + const { host, port } = config.database; return createConnection(host, port); }
अपने कोड में भेद्यताएँ खोजें
NULL Pointer Dereference पैटर्न के लिए अपने कोडबेस को स्कैन करने के लिए Shoulder का उपयोग करें। 2 नियम.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=476 # Or scan entire project npx @shoulderdev/cli trust .
पहचान नियम (2)
कोड समीक्षा में किन बातों पर ध्यान दें
ये पैटर्न संभावित NULL Pointer Dereference भेद्यताओं का संकेत देते हैं। कोड समीक्षा और सुरक्षा ऑडिट के दौरान इन्हें देखें।
अपने कोडबेस को इसके लिए स्कैन करें: NULL Pointer Dereference
Shoulder CLI आपके पूरे कोडबेस में भेद्य पैटर्न खोजता है।