rules:
- id: double-free
  patterns:
  - pattern-not: |
      free($VAR);
      ...
      $VAR = NULL;
      ...
      free($VAR);
  - pattern-not: |
      free($VAR);
      ...
      $VAR = malloc(...);
      ...
      free($VAR);
  - pattern-inside: |
      free($VAR);
      ...
      $FREE($VAR);
  - metavariable-pattern:
      metavariable: $FREE
      pattern: free
  - focus-metavariable: $FREE
  message: >-
    Variable '$VAR' was freed twice. This can lead to undefined behavior.
  metadata:
    cwe:
    - 'CWE-415: Double Free'
    owasp:
    - A03:2021 - Injection
    - A01:2017 - Injection
    references:
    - https://cwe.mitre.org/data/definitions/415.html
    - https://owasp.org/www-community/vulnerabilities/Doubly_freeing_memory
    category: security
    technology:
    - c
    confidence: LOW
    subcategory:
    - vuln
    likelihood: LOW
    impact: HIGH
  languages: [c]
  severity: ERROR
