ベータ Shoulder はベータ版です — 結果が誤っている場合があります。皆さまのフィードバックが次に修正する内容を決定します。 フィードバックを送る
🔒

NULL Pointer Dereference

🛡️ 2 件のルールが検出します

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.

普及度
2 言語をカバー
影響度
ミディアム
レビュー推奨
予防
文書化済み
2 件の修正例
2 予防
2 予防

この脆弱性の修正方法

Unsafe Type Assertion Without Ok Check MEDIUM

Use the two-value form of type assertion or type switch to handle failures gracefully

+7 -3 go
- 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
  }
  
Non-Null Assertion Without Null Check LOW

Replace non-null assertions (!) with explicit null checks or optional chaining

+4 -2 javascript
  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);
  }
  
3 検出
3 検出

コードの脆弱性を見つける

Shoulderを使用してコードのNULL Pointer Dereferenceパターンをスキャンしましょう。 2 ルール.

ターミナル
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=476

# Or scan entire project
npx @shoulderdev/cli trust .
4 警告サイン
4 警告サイン

コードレビューで注目すべき点

これらのパターンはNULL Pointer Dereferenceの潜在的な脆弱性を示しています。コードレビューとセキュリティ監査中に探してください。

🔵
Non-null assertion (!), used on '...' without explicit null/undefined check. This may cause runtime crashes if the value typescript-non-null-assertion
🔍

コードベースをスキャン: NULL Pointer Dereference

Shoulder CLI はコードベース全体から脆弱なパターンを見つけます。