Files
pruefwerk/compliance-agent/rules/vendor/0xdea/pack.yaml
T
sharangandClaude Opus 5.5 d406741907
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m13s
CI / Deploy Agent (push) Successful in 6m21s
feat(sast): vendored MIT semgrep packs and a guard against registry rules (#492) (#504)
Our ~35 own rules left whole languages without SAST findings. Three
permissively licensed community packs now run next to them, on the same
semgrep invocation (--metrics=off, local files only):

- GitLab sast-rules v2.10.1 (53bf5cf6): 148 rules for C#, Java,
  JavaScript/TypeScript, Python and one Go rule; only files whose header says
  "License: MIT (c) GitLab Inc.". Not vendored: c/ (every file GPL-2.0,
  generated from flawfinder), go/ apart from one file (Apache-2.0 gosec
  ports), scala/, rules/lgpl, rules/lgpl-cc (Commons Clause), rules/gitlab (EE).
- 0xdea semgrep-rules (dae50da6, MIT): 35 C/C++ rules.
- elttam semgrep-rules (24426856, MIT; its LICENSE carries the Semgrep
  template's copyright line): 34 rules for Java, Go and Struts/Spring XML.

Each pack lives in compliance-agent/rules/vendor/<source>/ with LICENSE,
NOTICE (provenance, what was left out and why) and UPSTREAM (pinned commit):
upstream/ holds the selected files unchanged with their tests, pack.yaml the
rules the agent runs, ids prefixed per source (gitlab-, 0xdea-, elttam-),
rules.json an index for the tests. scripts/vendor-semgrep-rules.py
regenerates all of it deterministically.

Provenance: every candidate rule was compared with the Semgrep registry
(semgrep/semgrep-rules, read only for the comparison). Eight GitLab Python/JS
rules with the same message or the same patterns are not vendored, nor are
elttam's Kubernetes rules (registry-derived). Also left out: elttam's
entrypoint enumerators, its ORM-leak hints, three files whose upstream
tests fail on semgrep 1.177 and a join-mode rule.

Noise budget: run over the nightly fixtures, the public samples and
FreeRTOS-Kernel, lwIP, OpenRA, eShopOnWeb, requests, express and
spring-petclinic. 15 rules that flood real code (0xdea missing-return 1514
hits, typos 989, interesting-api-calls 718, signed-unsigned-conversion 221,
suspicious-assert 176, format-string-bugs 61 ...; GitLab assert-used) are
dropped from the pack, each listed with its reason in NOTICE. CPU time of
the semgrep run roughly doubles on C-heavy trees (FreeRTOS-Kernel 70 s ->
136 s, lwIP 18 s -> 68 s), well inside the 10-minute stage timeout.

Ids stay bare (#473 logic covers the vendored ids, fingerprint() unchanged).
The control map gets one vendored semgrep binding per control, by CWE (by
rule id for the few elttam rules without one), with exactly the languages of
the rules behind it; a test checks every vendored rule maps to a control
that claims its languages.

Guard: semgrep_args() builds the one invocation; a test fails if any
--config is not a staged local pack, or is auto, p/, r/ or a URL, and
another scans the agent source, scripts, docker/, CI and Dockerfile.agent for
a registry config.

Nightly baselines with C, Python, C# or JS code change and need a bless run
after the image is deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-10-06 12:22:50 +00:00

2188 lines
61 KiB
YAML

# 0xdea semgrep-rules (C/C++), vendored by scripts/vendor-semgrep-rules.py; do not edit.
# Upstream: https://github.com/0xdea/semgrep-rules at dae50da6e6e629750f1daec73a01ef9206a372ab
# Licence: MIT; see LICENSE and NOTICE next to this file.
# Changed from upstream: ids prefixed with '0xdea-', rules
# left out as listed in NOTICE, rules re-serialised into one file.
rules:
- id: 0xdea-raptor-command-injection
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Command Injection
likelihood: MEDIUM
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-78: Improper Neutralization of Special Elements used in an OS Command (''OS Command Injection'')'
- 'CWE-88: Improper Neutralization of Argument Delimiters in a Command (''Argument Injection'')'
- 'CWE-676: Use of Potentially Dangerous Function'
owasp:
- A05:2025 - Injection
references:
- https://g.co/kgs/PCHQjJ
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
message: The software constructs an OS command using externally-influenced input, but it does not neutralize
or incorrectly neutralizes special elements that could modify the intended OS command.
severity: ERROR
patterns:
- pattern-either:
- pattern: system(...)
- pattern: popen(...)
- pattern: p2open(...)
- pattern: wordexp(...)
- pattern-not: $_("...", ...)
- id: 0xdea-raptor-double-free
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-415: Double Free'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://github.com/struct/mms
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
- https://dustri.org/b/playing-with-weggli.html
message: The software calls free() twice on the same memory address, potentially leading to memory corruption.
This corruption can cause the program to crash or cause two later calls to malloc() to return the same
pointer.
severity: ERROR
patterns:
- pattern: '$FREE1($PTR);
...
$FREE2($PTR);
'
- pattern-not: '$FREE1($PTR);
...
$PTR = ...;
...
$FREE2($PTR);
'
- metavariable-pattern:
metavariable: $FREE1
pattern: free
- metavariable-pattern:
metavariable: $FREE2
pattern: free
- focus-metavariable: $FREE2
- id: 0xdea-raptor-incorrect-order-setuid-setgid
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Improper Authorization
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-696: Incorrect Behavior Order'
owasp:
- A01:2025 - Broken Access Control
references:
- https://www.usenix.org/legacy/events/sec02/full_papers/chen/chen.pdf
- https://g.co/kgs/PCHQjJ
- https://github.com/struct/mms
message: A compromised process might be able to regain elevated group privileges if set(e)gid() is called
after set(e)uid(). A similar case is when privileges are temporarily dropped with seteuid() and then
setuid() or seteuid() are called from while under unprivileged user.
severity: ERROR
pattern-either:
- patterns:
- pattern: '<... setuid(...) ...>;
...
<... setgid(...) ...>;
'
- pattern-not: '<... setuid(0) ...>;
...
<... setgid(...) ...>;
'
- patterns:
- pattern: '<... seteuid(...) ...>;
...
<... setegid(...) ...>;
'
- pattern-not: '<... seteuid(0) ...>;
...
<... setegid(...) ...>;
'
- pattern-not-inside: '<... seteuid(...) ...>;
...
<... seteuid(0) ...>;
...
<... setegid(...) ...>;
'
- patterns:
- pattern: '<... seteuid(...) ...>;
...
<... setuid(...) ...>;
'
- pattern-not: '<... seteuid(0) ...>;
...
<... setuid(...) ...>;
'
- pattern-not-inside: '<... seteuid(...) ...>;
...
<... seteuid(0) ...>;
...
<... setuid(...) ...>;
'
- patterns:
- pattern: '<... seteuid(...) ...>;
...
<... seteuid(...) ...>;
'
- pattern-not: '<... seteuid(0) ...>;
...
<... seteuid(...) ...>;
'
- pattern-not: '<... seteuid(...) ...>;
...
<... seteuid(0) ...>;
'
- pattern-not-inside: '<... seteuid(...) ...>;
...
<... seteuid(0) ...>;
...
<... seteuid(...) ...>;
'
- id: 0xdea-raptor-incorrect-unsigned-comparison
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Improper Validation
likelihood: LOW
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-697: Incorrect Comparison'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: Checking if an unsigned variable is negative makes no sense and is usually a good indication
that something is probably wrong with the code.
severity: WARNING
pattern-either:
- pattern: (unsigned short $_) < 0
- pattern: (unsigned short int $_) < 0
- pattern: (unsigned int $_) < 0
- pattern: (unsigned long $_) < 0
- pattern: (unsigned long int $_) < 0
- pattern: (size_t $_) < 0
- pattern: (unsigned short $_) <= 0
- pattern: (unsigned short int $_) <= 0
- pattern: (unsigned int $_) <= 0
- pattern: (unsigned long $_) <= 0
- pattern: (unsigned long int $_) <= 0
- pattern: (size_t $_) <= 0
- pattern: (unsigned short $_) >= 0
- pattern: (unsigned short int $_) >= 0
- pattern: (unsigned int $_) >= 0
- pattern: (unsigned long $_) >= 0
- pattern: (unsigned long int $_) >= 0
- pattern: (size_t $_) >= 0
- id: 0xdea-raptor-incorrect-use-of-free
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-590: Free of Memory not on the Heap'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://github.com/shellphish/how2heap/blob/master/glibc_2.23/house_of_spirit.c
message: The software calls free() on a pointer to memory that has a short lifetime and was not allocated
using associated heap allocation functions such as malloc(), calloc(), or realloc().
severity: ERROR
pattern-either:
- patterns:
- pattern: free($PTR)
- pattern-either:
- pattern-inside: '$_ $PTR[$_];
...
'
- pattern-inside: '$_ $PTR[$_] = ...;
...
'
- pattern-inside: '$_ $PTR[] = ...;
...
'
- pattern-inside: '$_ $ARR[$_];
...
$PTR = $ARR;
...
'
- pattern-inside: '$_ $ARR[$_] = ...;
...
$PTR = $ARR;
...
'
- pattern-inside: '$_ $ARR[] = ...;
...
$PTR = $ARR;
...
'
- patterns:
- pattern: free(&$VAR)
- pattern-either:
- pattern-inside: '$_ $VAR;
...
'
- pattern-inside: '$_ $VAR = ...;
...
'
- pattern-inside: '$_ $VAR[$_];
...
'
- pattern-inside: '$_ $VAR[$_] = ...;
...
'
- pattern-inside: '$_ $VAR[] = ...;
...
'
- pattern-inside: '$_ * $VAR;
...
'
- pattern-inside: '$_ * $VAR = ...;
...
'
- id: 0xdea-raptor-incorrect-use-of-memset
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Mishandled Sensitive Information
likelihood: MEDIUM
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-683: Function Call With Incorrect Order of Arguments'
owasp:
- A04:2025 - Cryptographic Failures
references:
- https://lkml.org/lkml/2009/11/11/336
- https://bugs.mysql.com/bug.php?id=23181
message: The invocation of memset() is easy to get wrong. The second argument is the character and the
third argument is the size, but sometimes these arguments are in the wrong order. This results in a
no-op.
severity: ERROR
pattern-either:
- pattern: memset($_, $_, 0)
- pattern: memset($_, $_, '\0')
- pattern: memset($_, sizeof(...), $_)
- pattern: memset_explicit($_, $_, 0)
- pattern: memset_explicit($_, $_, '\0')
- pattern: memset_explicit($_, sizeof(...), $_)
- id: 0xdea-raptor-incorrect-use-of-sizeof
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-467: Use of sizeof() on a Pointer Type'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
- https://github.com/struct/mms
- https://dustri.org/b/playing-with-weggli.html
- https://mastodon.gamedev.place/@amonakov/111577826195014479
- https://github.com/semgrep/semgrep/issues/11327
message: The code calls sizeof() on a pointer type, which always returns the wordsize (8 on 64-bit architectures).
This can produce an unexpected result if the programmer intended to determine how much memory has
been allocated.
severity: WARNING
pattern-either:
- patterns:
- pattern: sizeof((char * $_))
- pattern-not: sizeof("...")
- pattern: sizeof((int * $_))
- pattern: sizeof((float * $_))
- pattern: sizeof((double * $_))
- patterns:
- pattern-either:
- pattern: sizeof($PTR)
- pattern: sizeof($PTR + $_)
- pattern: sizeof($_ + $PTR)
- pattern-either:
- pattern-inside: '$_ * $PTR;
...
'
- pattern-inside: '$_ * $PTR = ...;
...
'
- patterns:
- pattern-either:
- pattern: sizeof($PTR)
- pattern: sizeof($PTR + $_)
- pattern: sizeof($_ + $PTR)
- pattern-either:
- pattern-inside: "$_ $_(..., $_ * $PTR, ...) {\n ...\n}\n"
- pattern-inside: "$_ $_(..., $_ $PTR[$_], ...) {\n ...\n}\n"
- pattern-inside: "$_ $_(..., $_ $PTR[], ...) {\n ...\n}\n"
- pattern: sizeof(this)
- id: 0xdea-raptor-incorrect-use-of-strncat
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-787: Out-of-bounds Write'
- 'CWE-193: Off-by-one Error'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: 'The strncat() function is nearly as dangerous as strcat(), in that it''s quite easy to misuse.
The first common mistake is supplying the size of the entire buffer instead of the size remaining in
the buffer. A more subtle mistake can be made: the size parameter needs to be the amount of space left
in the buffer less one; otherwise, the NUL byte is written one byte past the end of the buffer.'
severity: ERROR
pattern-either:
- patterns:
- pattern: strncat($DST, $_, $LEN)
- pattern-either:
- pattern-inside: '$_ $DST[$LEN];
...
'
- pattern-inside: '$_ $DST[$LEN] = ...;
...
'
- pattern: strncat($DST, $_, sizeof($DST))
- pattern: strncat($DST, $_, strlen($DST))
- pattern: strncat($DST, $_, sizeof($DST) - strlen($DST))
- id: 0xdea-raptor-insecure-api-access-stat
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Dangerous Method or Function
likelihood: MEDIUM
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
- https://labs.snyk.io/resources/leaky-vessels-container-vuln-deep-dive/
message: The software checks the state of a resource before using it, but the resource's state can change
between the check and the use in a way that invalidates the results of the check. This can cause the
software to perform invalid actions when the resource is in an unexpected state.
severity: WARNING
pattern-either:
- pattern: access(...)
- pattern: faccessat(...)
- pattern: faccessat2(...)
- pattern: stat(...)
- pattern: lstat(...)
- pattern: fstatat(...)
- id: 0xdea-raptor-insecure-api-alloca
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Dangerous Method or Function
likelihood: MEDIUM
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-676: Use of Potentially Dangerous Function'
- 'CWE-1325: Improperly Controlled Sequential Memory Allocation'
owasp:
- A06:2025 - Insecure Design
references:
- https://nullprogram.com/blog/2019/10/28/
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
message: Use of alloca() is unsafe because it cannot ensure that the pointer returned points to a valid
and usable block of memory. The allocation made may exceed the bounds of the stack, or even go further
into other objects in memory, and alloca() cannot determine such an error.
severity: ERROR
pattern: alloca(...)
- id: 0xdea-raptor-insecure-api-ato
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Dangerous Method or Function
likelihood: LOW
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-839: Numeric Range Comparison Without Minimum Check'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://rules.sonarsource.com/c/type/Bug/RSPEC-989
- https://wiki.sei.cmu.edu/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number
- https://github.com/vixie/cron/commit/9cc8ab1087bb9ab861dd5595c41200683c9f6712
message: The atoi(), atol(), atof(), and similar functions don't handle errors. They don't check for integer
overflow and can return a negative value. They have undefined behavior if the value of the result cannot
be represented. They return 0 (or 0.0) if the string does not represent an integer (or decimal), which
is indistinguishable from a correctly formatted, zero-denoting input string.
severity: INFO
pattern-either:
- pattern: atoi(...)
- pattern: atol(...)
- pattern: atof(...)
- pattern: atoll(...)
- id: 0xdea-raptor-insecure-api-gets
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Dangerous Method or Function
likelihood: HIGH
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-242: Use of Inherently Dangerous Function'
- 'CWE-120: Buffer Copy without Checking Size of Input (''Classic Buffer Overflow'')'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: The gets() function is always unsafe because it does not perform bounds checking on the size
of its input. An attacker can easily send arbitrarily-sized input to gets() and overflow the destination
buffer.
severity: ERROR
pattern: gets(...)
- id: 0xdea-raptor-insecure-api-mktemp-tmpnam-tempnam
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Dangerous Method or Function
likelihood: MEDIUM
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-377: Insecure Temporary File'
- 'CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: Creating and using insecure temporary files can leave application and system data vulnerable
to attack.
severity: WARNING
pattern-either:
- pattern: mktemp(...)
- pattern: tmpnam(...)
- pattern: tempnam(...)
- pattern: tmpnam_r(...)
- id: 0xdea-raptor-insecure-api-rand-srand
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Cryptographic Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)'
- 'CWE-330: Use of Insufficiently Random Values'
owasp:
- A04:2025 - Cryptographic Failures
references:
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
message: The rand() PRNG should not be used in applications intended to be portable when good randomness
is needed. Instead, the use of random() is recommended.
severity: WARNING
pattern-either:
- pattern: rand(...)
- pattern: srand(...)
- pattern: drand48(...)
- pattern: erand48(...)
- pattern: lrand48(...)
- pattern: nrand48(...)
- pattern: mrand48(...)
- pattern: jrand48(...)
- pattern: lcong48(...)
- pattern: srand48(...)
- pattern: seed48(...)
- id: 0xdea-raptor-insecure-api-scanf
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Dangerous Method or Function
likelihood: HIGH
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-676: Use of Potentially Dangerous Function'
- 'CWE-120: Buffer Copy without Checking Size of Input (''Classic Buffer Overflow'')'
- 'CWE-787: Out-of-bounds Write'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: A buffer overflow condition exists when a program attempts to put more data in a buffer than
it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a
buffer.
severity: ERROR
patterns:
- pattern-either:
- pattern: scanf($FMT, ...)
- pattern: __isoc99_scanf($FMT, ...)
- pattern: vscanf($FMT, ...)
- pattern: __isoc99_vscanf($FMT, ...)
- pattern: fscanf($_, $FMT, ...)
- pattern: __isoc99_fscanf($_, $FMT, ...)
- pattern: vfscanf($_, $FMT, ...)
- pattern: __isoc99_vfscanf($_, $FMT, ...)
- pattern: sscanf($_, $FMT, ...)
- pattern: __isoc99_sscanf($_, $FMT, ...)
- pattern: vsscanf($_, $FMT, ...)
- pattern: __isoc99_vsscanf($_, $FMT, ...)
- pattern: wscanf($FMT, ...)
- pattern: vwscanf($FMT, ...)
- pattern: fwscanf($_, $FMT, ...)
- pattern: vfwscanf($_, $FMT, ...)
- pattern: swscanf($_, $FMT, ...)
- pattern: vswscanf($_, $FMT, ...)
- pattern-not: sscanf("...", $FMT, ...)
- pattern-not: __isoc99_sscanf("...", $FMT, ...)
- pattern-not: vsscanf("...", $FMT, ...)
- pattern-not: __isoc99_vsscanf("...", $FMT, ...)
- pattern-not: swscanf("...", $FMT, ...)
- pattern-not: vswscanf("...", $FMT, ...)
- metavariable-regex:
metavariable: $FMT
regex: (".*%l?s.*"|".*%S.*"|[a-zA-Z_][a-zA-Z0-9_]*)
- id: 0xdea-raptor-insecure-api-signal
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Dangerous Method or Function
likelihood: MEDIUM
impact: MEDIUM
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-364: Signal Handler Race Condition'
- 'CWE-479: Signal Handler Use of a Non-reentrant Function'
- 'CWE-828: Signal Handler with Functionality that is not Asynchronous-Safe'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://lcamtuf.coredump.cx/signals.txt
message: The signal() API should be regarded as deprecated. When possible, sigaction() should be used
instead, because it allows to precisely specify the desired behavior in case two signals arrive shortly
after each other thus preventing many race conditions.
severity: WARNING
pattern-either:
- pattern: signal(...)
- pattern: gsignal(...)
- pattern: ssignal(...)
- id: 0xdea-raptor-insecure-api-sprintf-vsprintf
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Dangerous Method or Function
likelihood: HIGH
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-676: Use of Potentially Dangerous Function'
- 'CWE-120: Buffer Copy without Checking Size of Input (''Classic Buffer Overflow'')'
- 'CWE-787: Out-of-bounds Write'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: A buffer overflow condition exists when a program attempts to put more data in a buffer than
it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a
buffer.
severity: ERROR
patterns:
- pattern-either:
- pattern: sprintf($_, $FMT, ...)
- pattern: vsprintf($_, $FMT, ...)
- metavariable-regex:
metavariable: $FMT
regex: (".*%l?s.*"|".*%S.*"|[a-zA-Z_][a-zA-Z0-9_]*)
- id: 0xdea-raptor-insecure-api-strcpy-strcat
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Dangerous Method or Function
likelihood: HIGH
impact: HIGH
confidence: HIGH
technology:
- c
- cpp
cwe:
- 'CWE-676: Use of Potentially Dangerous Function'
- 'CWE-120: Buffer Copy without Checking Size of Input (''Classic Buffer Overflow'')'
- 'CWE-787: Out-of-bounds Write'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
message: A buffer overflow condition exists when a program attempts to put more data in a buffer than
it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a
buffer.
severity: ERROR
patterns:
- pattern-either:
- pattern: strcpy(...)
- pattern: stpcpy(...)
- pattern: strcat(...)
- pattern: wcscpy(...)
- pattern: wcpcpy(...)
- pattern: wcscat(...)
- pattern: _mbscpy(...)
- pattern: _mbscat(...)
- pattern: strccpy(...)
- pattern: strcadd(...)
- pattern: streadd(...)
- pattern: strecpy(...)
- pattern: strtrns(...)
- pattern-not: $_($_, "...", ...)
- id: 0xdea-raptor-integer-wraparound
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-190: Integer Overflow or Wraparound'
- 'CWE-128: Wrap-around Error'
- 'CWE-131: Incorrect Calculation of Buffer Size'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
- http://www.phrack.org/issues/60/10.html#article
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
- https://dustri.org/b/playing-with-weggli.html
message: The software performs a calculation that can produce an integer overflow or wraparound, when
the logic assumes that the resulting value will always be larger than the original value. This can introduce
other weaknesses when the calculation is used for resource management or execution control.
severity: WARNING
pattern-either:
- patterns:
- pattern-either:
- pattern: $FUN($_ * $_)
- pattern: $FUN($_ *= $_)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: malloc
- pattern: valloc
- patterns:
- pattern: $FUN($N)
- pattern-either:
- pattern-inside: '$N = $_ * $_;
...
'
- pattern-inside: '$N *= $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: malloc
- pattern: valloc
- patterns:
- pattern-either:
- pattern: $FUN($_ + $_)
- pattern: $FUN($_ += $_)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: malloc
- pattern: valloc
- patterns:
- pattern: $FUN($N)
- pattern-either:
- pattern-inside: '$N = $_ + $_;
...
'
- pattern-inside: '$N += $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: malloc
- pattern: valloc
- patterns:
- pattern-either:
- pattern: $FUN($_, $_ * $_, ...)
- pattern: $FUN($_, $_ *= $_, ...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- pattern: realloc
- pattern: reallocf
- pattern: aligned_alloc
- pattern: VirtualAlloc
- patterns:
- pattern: $FUN($_, $N, ...)
- pattern-either:
- pattern-inside: '$N = $_ * $_;
...
'
- pattern-inside: '$N *= $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- pattern: realloc
- pattern: reallocf
- pattern: aligned_alloc
- pattern: VirtualAlloc
- patterns:
- pattern-either:
- pattern: $FUN($_, $_ + $_, ...)
- pattern: $FUN($_, $_ += $_, ...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- pattern: realloc
- pattern: reallocf
- pattern: aligned_alloc
- pattern: VirtualAlloc
- patterns:
- pattern: $FUN($_, $N, ...)
- pattern-either:
- pattern-inside: '$N = $_ + $_;
...
'
- pattern-inside: '$N += $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- pattern: realloc
- pattern: reallocf
- pattern: aligned_alloc
- pattern: VirtualAlloc
- patterns:
- pattern-either:
- pattern: $FUN($_ * $_, $_)
- pattern: $FUN($_ *= $_, $_)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- patterns:
- pattern: $FUN($N, $_)
- pattern-either:
- pattern-inside: '$N = $_ * $_;
...
'
- pattern-inside: '$N *= $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- patterns:
- pattern-either:
- pattern: $FUN($_ + $_, $_)
- pattern: $FUN($_ += $_, $_)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- patterns:
- pattern: $FUN($N, $_)
- pattern-either:
- pattern-inside: '$N = $_ + $_;
...
'
- pattern-inside: '$N += $_;
...
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: calloc
- pattern: $X > $MAX || ($X + $_) > $MAX
- pattern: $X >= $MAX || ($X + $_) > $MAX
- pattern: $X > $MAX || ($X + $_) >= $MAX
- pattern: $X >= $MAX || ($X + $_) >= $MAX
- pattern: $X < $MAX && ($X + $_) < $MAX
- pattern: $X <= $MAX && ($X + $_) < $MAX
- pattern: $X < $MAX && ($X + $_) <= $MAX
- pattern: $X <= $MAX && ($X + $_) <= $MAX
- pattern: $X > $MAX || ($X * $_) > $MAX
- pattern: $X >= $MAX || ($X * $_) > $MAX
- pattern: $X > $MAX || ($X * $_) >= $MAX
- pattern: $X >= $MAX || ($X * $_) >= $MAX
- pattern: $X < $MAX && ($X * $_) < $MAX
- pattern: $X <= $MAX && ($X * $_) < $MAX
- pattern: $X < $MAX && ($X * $_) <= $MAX
- pattern: $X <= $MAX && ($X * $_) <= $MAX
- id: 0xdea-raptor-memory-address-exposure
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Mishandled Sensitive Information
likelihood: LOW
impact: MEDIUM
confidence: LOW
technology:
- c
- cpp
cwe:
- 'CWE-209: Generation of Error Message Containing Sensitive Information'
- 'CWE-497: Exposure of Sensitive System Information to an Unauthorized Control Sphere'
owasp:
- A04:2025 - Cryptographic Failures
references:
- https://github.com/struct/mms
message: The software generates an error message that includes sensitive information about its environment,
users, or associated data. In particular, exposure of memory addresses might defeat ASLR.
severity: INFO
patterns:
- pattern-either:
- pattern: printf($FMT, ...)
- pattern: vprintf($FMT, ...)
- pattern: wprintf($FMT, ...)
- pattern: vwprintf($FMT, ...)
- pattern: vcprintf($FMT, ...)
- pattern: vcwprintf($FMT, ...)
- pattern: vscprintf($FMT, ...)
- pattern: vscwprintf($FMT, ...)
- pattern: printk($FMT, ...)
- pattern: warn($FMT, ...)
- pattern: vwarn($FMT, ...)
- pattern: warnx($FMT, ...)
- pattern: vwarnx($FMT, ...)
- pattern: fprintf($_, $FMT, ...)
- pattern: vfprintf($_, $FMT, ...)
- pattern: fwprintf($_, $FMT, ...)
- pattern: vfwprintf($_, $FMT, ...)
- pattern: sprintf($_, $FMT, ...)
- pattern: vsprintf($_, $FMT, ...)
- pattern: asprintf($_, $FMT, ...)
- pattern: vasprintf($_, $FMT, ...)
- pattern: dprintf($_, $FMT, ...)
- pattern: vdprintf($_, $FMT, ...)
- pattern: wsprintf($_, $FMT, ...)
- pattern: syslog($_, $FMT, ...)
- pattern: vsyslog($_, $FMT, ...)
- pattern: err($_, $FMT, ...)
- pattern: verr($_, $FMT, ...)
- pattern: errx($_, $FMT, ...)
- pattern: verrx($_, $FMT, ...)
- pattern: warnc($_, $FMT, ...)
- pattern: vwarnc($_, $FMT, ...)
- pattern: snprintf($_, $_, $FMT, ...)
- pattern: vsnprintf($_, $_, $FMT, ...)
- pattern: swprintf($_, $_, $FMT, ...)
- pattern: vswprintf($_, $_, $FMT, ...)
- pattern: errc($_, $_, $FMT, ...)
- pattern: verrc($_, $_, $FMT, ...)
- metavariable-regex:
metavariable: $FMT
regex: (".*%\w*x.*"|".*%\w*X.*"|".*%\w*p.*")
- id: 0xdea-raptor-mismatched-memory-management-cpp
languages: [cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: LOW
impact: MEDIUM
confidence: LOW
technology:
- cpp
cwe:
- 'CWE-762: Mismatched Memory Management Routines'
owasp:
- A06:2025 - Insecure Design
references:
- https://github.com/struct/mms
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
message: The software attempts to return a memory resource to the system, but it calls a release function
that is not compatible with the function that was originally used to allocate that resource. Due to
inherent limitations of Semgrep, this rule might generate many false positives and should therefore
be customized for your codebase.
severity: INFO
pattern-either:
- patterns:
- pattern: free($PTR)
- pattern-not-inside: '$PTR = malloc(...);
...
'
- pattern-not-inside: '$PTR = calloc(...);
...
'
- pattern-not-inside: '$PTR = realloc(...);
...
'
- pattern-not-inside: '$PTR = strdup(...);
...
'
- pattern-not-inside: '$PTR = strndup(...);
...
'
- patterns:
- pattern: delete[]($PTR)
- pattern-not-inside: '$PTR = new $_[$_];
...
'
- patterns:
- pattern: delete($PTR)
- pattern-not-inside: '$PTR = new $_;
...
'
- patterns:
- pattern: delete($PTR)
- pattern-inside: '$PTR = new $_[$_];
...
'
- id: 0xdea-raptor-off-by-one
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-193: Off-by-one Error'
- 'CWE-787: Out-of-bounds Write'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
- https://github.com/struct/mms
message: The software calculates or uses an incorrect maximum or minimum value that is 1 more, or 1 less,
than the correct value.
severity: WARNING
pattern-either:
- pattern: $BUF[sizeof($BUF)] = ...
- patterns:
- pattern: $BUF[$LEN] = ...
- pattern-either:
- pattern-inside: '$_ $BUF[$LEN];
...
'
- pattern-inside: '$_ $BUF[$LEN] = ...;
...
'
- patterns:
- pattern: '*($BUF + $LEN) = ...
'
- pattern-either:
- pattern-inside: '$_ $BUF[$LEN];
...
'
- pattern-inside: '$_ $BUF[$LEN] = ...;
...
'
- patterns:
- pattern: $BUF[$X][$Y] = ...
- pattern-either:
- pattern-inside: '$_ $BUF[$_][$Y];
...
'
- pattern-inside: '$_ $BUF[$X][$_];
...
'
- pattern: strlen($SRC) > sizeof($DST)
- pattern: strlen($SRC) <= sizeof($DST)
- pattern: sizeof($DST) < strlen($SRC)
- pattern: sizeof($DST) >= strlen($SRC)
- patterns:
- pattern: strncat($_, $_, $LEN)
- metavariable-pattern:
metavariable: $LEN
patterns:
- pattern-not: $_ - 1
- pattern: $STR[strlen($STR) - 1]
- patterns:
- pattern-inside: '$LEN = strlen($STR) - 1;
...
'
- pattern: $STR[$LEN]
- patterns:
- pattern-inside: '$LEN = strlen($STR);
...
'
- pattern: $STR[$LEN - 1]
- pattern: malloc(strlen($STR))
- patterns:
- pattern-inside: '$LEN = strlen($STR);
...
'
- pattern: malloc($LEN)
- id: 0xdea-raptor-overlapping-source-destination
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: LOW
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-1260: Improper Handling of Overlap Between Protected Memory Ranges'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://linux.die.net/man/3/sprintf
message: C standards specify that the results are undefined if a call to copy functions, with the exception
of memmove(), would cause copying to take place between objects that overlap (e.g., if the target string
array and one of the supplied input arguments refer to the same buffer).
severity: WARNING
pattern-either:
- patterns:
- pattern: $FUN($DST, $DST, ...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strcpy
- pattern: strncpy
- pattern: stpcpy
- pattern: stpncpy
- pattern: strlcpy
- pattern: strscpy
- pattern: wcscpy
- pattern: wcsncpy
- pattern: wcpcpy
- pattern: wcpncpy
- pattern: wcslcpy
- pattern: _mbscpy
- pattern: _mbsncpy
- pattern: _mbpcpy
- pattern: _mbpncpy
- pattern: _mbslcpy
- pattern: strccpy
- pattern: strcadd
- pattern: streadd
- pattern: strecpy
- pattern: strcat
- pattern: strncat
- pattern: strlcat
- pattern: wcscat
- pattern: wcsncat
- pattern: wcslcat
- pattern: _mbscat
- pattern: _mbsncat
- pattern: _mbslcat
- pattern: memcpy
- pattern: memccpy
- pattern: wmemcpy
- pattern: mempcpy
- pattern: wmempcpy
- pattern: bcopy
- pattern: sprintf($DST, ..., $DST, ...)
- pattern: snprintf($DST, $_, ..., $DST, ...)
- id: 0xdea-raptor-putenv-stack-var
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-686: Function Call With Incorrect Argument Type'
- 'CWE-562: Return of Stack Variable Address'
owasp:
- A06:2025 - Insecure Design
references:
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
message: The software calls putenv() with a variable that has a short lifetime, such as a pointer to an
automatic variable allocated on the stack. The correct behavior is to call putenv() with a static/global
string.
severity: INFO
patterns:
- pattern: putenv($PTR)
- pattern-either:
- patterns:
- pattern-inside: '$_ $PTR[$_];
...
'
- pattern-not-inside: 'static $_ $PTR[$_];
...
'
- patterns:
- pattern-inside: '$_ $PTR[$_] = ...;
...
'
- pattern-not-inside: 'static $_ $PTR[$_] = ...;
...
'
- patterns:
- pattern-inside: '$_ $PTR[] = ...;
...
'
- pattern-not-inside: 'static $_ $PTR[] = ...;
...
'
- patterns:
- pattern-inside: '$_ $ARR[$_];
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[$_];
...
'
- patterns:
- pattern-inside: '$_ $ARR[$_] = ...;
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[$_] = ...;
...
'
- patterns:
- pattern-inside: '$_ $ARR[] = ...;
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[] = ...;
...
'
- id: 0xdea-raptor-regex-dos
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Denial-of-Service (DoS)
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-1333: Inefficient Regular Expression Complexity'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://semgrep.dev/docs/writing-rules/metavariable-analysis
- https://github.com/semgrep/semgrep/pull/4672
message: The software uses a regular expression with an inefficient, possibly exponential worst-case computational
complexity that consumes excessive CPU cycles. Poorly constructed regular expressions that exhibit exponential
runtime when fed specifically crafted inputs can cause RegEx denial of service (ReDoS).
severity: WARNING
patterns:
- pattern-either:
- pattern: $FUN($_, $REGEX, $_)
- pattern: '$STRING = $REGEX;
...
<... $FUN($_, $STRING, $_) ...>;
'
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: regcomp
- pattern: regncomp
- pattern: regwcomp
- pattern: regwncomp
- pattern: regcomp_l
- pattern: regncomp_l
- pattern: regwcomp_l
- pattern: regwncomp_l
- metavariable-analysis:
analyzer: redos
metavariable: $REGEX
- focus-metavariable: $REGEX
- id: 0xdea-raptor-ret-stack-address
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: LOW
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-562: Return of Stack Variable Address'
owasp:
- A06:2025 - Insecure Design
references:
- https://github.com/struct/mms
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
- https://rules.sonarsource.com/c/type/Bug/RSPEC-946
message: A function returns the address of a stack variable, which will cause unintended program behavior,
typically in the form of a crash.
severity: INFO
pattern-either:
- patterns:
- pattern: return $PTR;
- pattern-either:
- patterns:
- pattern-inside: '$_ $PTR[$_];
...
'
- pattern-not-inside: 'static $_ $PTR[$_];
...
'
- patterns:
- pattern-inside: '$_ $PTR[$_] = ...;
...
'
- pattern-not-inside: 'static $_ $PTR[$_] = ...;
...
'
- patterns:
- pattern-inside: '$_ $PTR[] = ...;
...
'
- pattern-not-inside: 'static $_ $PTR[] = ...;
...
'
- patterns:
- pattern-inside: '$_ $ARR[$_];
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[$_];
...
'
- patterns:
- pattern-inside: '$_ $ARR[$_] = ...;
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[$_] = ...;
...
'
- patterns:
- pattern-inside: '$_ $ARR[] = ...;
...
$PTR = $ARR;
...
'
- pattern-not-inside: 'static $_ $ARR[] = ...;
...
'
- patterns:
- pattern: return &$VAR;
- pattern-either:
- patterns:
- pattern-inside: '$_ $VAR;
...
'
- pattern-not-inside: 'static $_ $VAR;
...
'
- patterns:
- pattern-inside: '$_ $VAR = ...;
...
'
- pattern-not-inside: 'static $_ $VAR = ...;
...
'
- patterns:
- pattern-inside: '$_ $VAR[$_];
...
'
- pattern-not-inside: 'static $_ $VAR[$_];
...
'
- patterns:
- pattern-inside: '$_ $VAR[$_] = ...;
...
'
- pattern-not-inside: 'static $_ $VAR[$_] = ...;
...
'
- patterns:
- pattern-inside: '$_ $VAR[] = ...;
...
'
- pattern-not-inside: 'static $_ $VAR[] = ...;
...
'
- patterns:
- pattern-inside: '$_ * $VAR;
...
'
- pattern-not-inside: 'static $_ * $VAR;
...
'
- patterns:
- pattern-inside: '$_ * $VAR = ...;
...
'
- pattern-not-inside: 'static $_ * $VAR = ...;
...
'
- id: 0xdea-raptor-unchecked-ret-malloc
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-252: Unchecked Return Value'
- 'CWE-690: Unchecked Return Value to NULL Pointer Dereference'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
- https://github.com/struct/mms
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
message: The software does not check the return value from a method or function, which can prevent it
from detecting unexpected states and conditions.
severity: WARNING
patterns:
- pattern-either:
- pattern: $RET = $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: malloc
- pattern: calloc
- pattern: realloc
- pattern: reallocf
- pattern: valloc
- pattern: aligned_alloc
- pattern: strdup
- pattern: strndup
- pattern-not-inside: '$FUN(...);
...
if (<... $RET ...>) ...
'
- pattern-not-inside: <... $_ == NULL ...>
- pattern-not-inside: <... NULL == $_ ...>
- pattern-not-inside: <... $_ != NULL ...>
- pattern-not-inside: <... NULL != $_ ...>
- pattern-not-inside: <... !$_ ...>
- id: 0xdea-raptor-unchecked-ret-scanf
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Other Security
likelihood: MEDIUM
impact: LOW
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-252: Unchecked Return Value'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://codeql.github.com/codeql-query-help/cpp/cpp-missing-check-scanf/
message: The software does not check the return value from a method or function, which can prevent it
from detecting unexpected states and conditions.
severity: WARNING
patterns:
- pattern: $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: scanf
- pattern: __isoc99_scanf
- pattern: vscanf
- pattern: __isoc99_vscanf
- pattern: fscanf
- pattern: __isoc99_fscanf
- pattern: vfscanf
- pattern: __isoc99_vfscanf
- pattern: sscanf
- pattern: __isoc99_sscanf
- pattern: vsscanf
- pattern: __isoc99_vsscanf
- pattern: wscanf
- pattern: vwscanf
- pattern: fwscanf
- pattern: vfwscanf
- pattern: swscanf
- pattern: vswscanf
- pattern-not-inside: $_ = $FUN(...)
- pattern-not-inside: <... $FUN(...) == $_ ...>
- pattern-not-inside: <... $_ == $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) != $_ ...>
- pattern-not-inside: <... $_ != $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) < $_ ...>
- pattern-not-inside: <... $_ > $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) <= $_ ...>
- pattern-not-inside: <... $_ >= $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) > $_ ...>
- pattern-not-inside: <... $_ < $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) >= $_ ...>
- pattern-not-inside: <... $_ <= $FUN(...) ...>
- pattern-not-inside: return $FUN(...);
- id: 0xdea-raptor-unchecked-ret-setuid-seteuid
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Improper Authorization
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-252: Unchecked Return Value'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://lwn.net/Articles/451985/
- https://www.usenix.org/legacy/events/sec02/full_papers/chen/chen.pdf
- https://www.openwall.com/lists/oss-security/2023/12/30/4
message: The software does not check the return value from a method or function, which can prevent it
from detecting unexpected states and conditions. If the program calls a function to drop privileges
but does not check the return code to ensure that privileges were successfully dropped, then the program
will continue to operate with the higher privileges.
severity: WARNING
patterns:
- pattern: $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: setuid
- pattern: seteuid
- pattern-not-inside: $_ = $FUN(...)
- pattern-not-inside: <... $FUN(...) == $_ ...>
- pattern-not-inside: <... $_ == $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) != $_ ...>
- pattern-not-inside: <... $_ != $FUN(...) ...>
- pattern-not-inside: <... $FUN(...) < $_ ...>
- pattern-not-inside: <... $_ > $FUN(...) ...>
- pattern-not-inside: <... !$FUN(...) ...>
- pattern-not-inside: return $FUN(...);
- id: 0xdea-raptor-unsafe-ret-snprintf-vsnprintf
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-131: Incorrect Calculation of Buffer Size'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://lwn.net/Articles/507319/
- https://g.co/kgs/PCHQjJ
- https://dustri.org/b/playing-with-weggli.html
message: The snprintf() and vsnprintf() functions return the total length of the string they tried to
create. Therefore, this return value can be larger than the size of the destination buffer. If it is
used unsafely, e.g. as an index to write to the destination buffer, memory corruption might occur.
severity: WARNING
patterns:
- pattern-either:
- pattern: $_ = $FUN($_, $_, $FMT, ...)
- pattern: $_ += $FUN($_, $_, $FMT, ...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: snprintf
- pattern: vsnprintf
- metavariable-regex:
metavariable: $FMT
regex: (".*%l?s.*"|".*%S.*"|[a-zA-Z_][a-zA-Z0-9_]*)
- id: 0xdea-raptor-unsafe-ret-strlcpy-strlcat
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- audit
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-131: Incorrect Calculation of Buffer Size'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://lwn.net/Articles/507319/
- https://g.co/kgs/PCHQjJ
message: The strlcpy() and strlcat() functions return the total length of the string they tried to create.
For strlcpy() that means the length of the source string. For strlcat() that means the initial length
of the destination string plus the length of of the source string. Therefore, this return value can
be larger than the size of the destination buffer. If it is used unsafely, e.g. as an index to write
to the destination buffer, memory corruption might occur.
severity: WARNING
patterns:
- pattern-either:
- pattern: $_ = $FUN(...)
- pattern: $_ += $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strlcpy
- pattern: strlcat
- pattern: wcslcpy
- pattern: wcslcat
- pattern: _mbslcpy
- pattern: _mbslcat
- id: 0xdea-raptor-unsafe-strlen
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Other Security
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-190: Integer Overflow or Wraparound'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://github.com/struct/mms
message: The software performs a calculation that can produce an integer overflow or wraparound, when
the logic assumes that the resulting value will always be larger than the original value. This can introduce
other weaknesses when the calculation is used for resource management or execution control. When influenced
by the size of an input it is often easier to overflow a short than an int.
severity: WARNING
patterns:
- pattern-either:
- pattern: (short $_) = $FUN(...)
- pattern: (short int $_) = $FUN(...)
- pattern: (unsigned short $_) = $FUN(...)
- pattern: (unsigned short int $_) = $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strlen
- pattern: lstrlen
- pattern: strnlen
- pattern: wcslen
- pattern: wcsnlen
- id: 0xdea-raptor-unterminated-string-strncpy
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-170: Improper Null Termination'
- 'CWE-126: Buffer Over-read'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://g.co/kgs/PCHQjJ
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
message: If there is no NUL character byte in the first n bytes of the source string, strncpy() and stpncpy()
do not NUL-terminate the destination buffer. If the program does not explicitly terminate the destination
buffer, this will almost certainly result in information disclosure, and possibly a buffer overflow
condition.
severity: WARNING
patterns:
- pattern: $FUN(...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strncpy
- pattern: stpncpy
- pattern: wcsncpy
- pattern: wcpncpy
- pattern: _mbsncpy
- pattern-not-inside: '$FUN($DST, $_, $_);
...
$DST[$_] = NULL;
'
- pattern-not-inside: '$FUN($DST, $_, $_);
...
$DST[$_] = ''\0'';
'
- pattern-not-inside: '$FUN($DST, $_, $_);
...
$DST[$_] = 0;
'
- id: 0xdea-raptor-use-after-free
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-416: Use After Free'
owasp:
- A10:2025 - Mishandling of Exceptional Conditions
references:
- https://github.com/struct/mms
- https://www.sei.cmu.edu/downloads/sei-cert-c-coding-standard-2016-v01.pdf
- https://docs.microsoft.com/en-us/cpp/sanitizers/asan-error-examples
message: The use of previously-freed memory can have any number of adverse consequences, ranging from
the corruption of valid data to the execution of arbitrary code, depending on the instantiation and
timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed
memory.
severity: ERROR
patterns:
- pattern-either:
- pattern: $PTR->$_
- pattern: $PTR[$_]
- pattern: (*$PTR)
- pattern: return $PTR;
- patterns:
- pattern-either:
- pattern: $FUN(..., <... $PTR ...>, ...)
- pattern: $PTR->$FUN(...)
- metavariable-pattern:
metavariable: $FUN
patterns:
- pattern-not: free
- pattern-inside: free($PTR); ...
- pattern-not-inside: "free($PTR);\n...\n$PTR = ...; \n...\n"
- id: 0xdea-raptor-use-of-source-size-in-copy
languages: [c, cpp]
metadata:
author: Marco Ivaldi <raptor@0xdeadbeef.info>
category: security
subcategory:
- vuln
vulnerability_class: Memory Issues
likelihood: MEDIUM
impact: HIGH
confidence: MEDIUM
technology:
- c
- cpp
cwe:
- 'CWE-806: Buffer Access Using Size of Source Buffer'
owasp:
- A06:2025 - Insecure Design
references:
- https://github.com/0xdea/advisories/blob/master/2020-07-solaris-whodo-w.txt
- https://dustri.org/b/playing-with-weggli.html
message: The software uses the size of a source buffer when reading from or writing to a destination buffer,
which may cause it to access memory that is outside of the bounds of the buffer.
severity: ERROR
pattern-either:
- patterns:
- pattern: $FUN($DST, $SRC, $LEN)
- pattern-not: $FUN($DST, "...", $LEN)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strncpy
- pattern: stpncpy
- pattern: strlcpy
- pattern: strscpy
- pattern: memcpy
- pattern: memmove
- pattern: wmemcpy
- pattern: wmemmove
- pattern: mempcpy
- pattern: wmempcpy
- pattern-either:
- patterns:
- pattern-inside: '$_ $SRC[$LEN];
...
'
- pattern-not-inside: '$_ $DST[$LEN];
...
'
- pattern-not-inside: '$_ $DST[$LEN] = ...;
...
'
- patterns:
- pattern-inside: '$_ $SRC[$LEN] = ...;
...
'
- pattern-not-inside: '$_ $DST[$LEN];
...
'
- pattern-not-inside: '$_ $DST[$LEN] = ...;
...
'
- patterns:
- pattern: $FUN($DST, $SRC, <... $SRC ...>)
- pattern-not: $FUN($DST, "...", <... $SRC ...>)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: strncpy
- pattern: stpncpy
- pattern: strlcpy
- pattern: strscpy
- pattern: memcpy
- pattern: memmove
- pattern: wmemcpy
- pattern: wmemmove
- pattern: mempcpy
- pattern: wmempcpy
- patterns:
- pattern: $FUN($DST, <... $SRC ...>, ..., $SRC, ...)
- metavariable-pattern:
metavariable: $FUN
pattern-either:
- pattern: snprintf
- pattern: vsnprintf
- pattern: swprintf
- pattern: vswprintf