Skip to content

[Query Create]: CWE-252, CWE-369, CWE-457, CWE-476, CWE-571 MEDIUM - C/C++: new query for missing input validation, NULL and numeric checks #254

Open

Description

@felickz

Target Language

cpp

Query Name (Optional)

InputValidationNullNumeric

Query Type

Security

Query Description

AI Scan reported 19 medium and low-severity CWE-252, CWE-369, CWE-457, CWE-476, CWE-571 (input validation null numeric) finding(s) in C/C++ public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-query, missing-source-file-read-no-zero-check, query-absent-argv-without-argc-check, missing-source-socket-recv-atoi, query-absent, logic-flaw-not-dataflow, scope-condition-malloc-deref-before-check, scope-condition, missing-function-model-read, missing-function-model-impersonation. Existing queries considered: cpp/divide-by-zero, cpp/redundant-null-check-simple, cpp/constant-comparison, cpp/missing-null-test, cpp/dereference-before-null-check, cpp/uninitialized-local, cpp/unchecked-return-value.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • No installed C/C++ security query covers unchecked attacker-controlled division. A focused rule is feasible, but treating every unchecked divisor as security-sensitive would reduce precision.
  • 369 pattern: img.height is read directly from the input file and used as a divisor without a zero check, causing SIGFPE (denial of service) for a crafted file.
  • 476 pattern: main dereferences argv[1] without checking argc, resulting in a NULL pointer being passed to fopen.
  • 476 pattern: main passes argv[1] to ProcessImage without checking argc, dereferencing a NULL pointer when no argument is supplied.
  • 476 pattern: main dereferences argv[1] without checking argc, passing NULL to ProcessImage/fopen when invoked without arguments.
  • 476 pattern: main dereferences argv[1] without verifying argc >= 2; running the program without arguments passes a NULL pointer into ProcessImage, which then calls fopen(NULL, "r").

Linked findings (gap-key: cpp/query-create/input-validation-null-numeric)

Repo CWE Severity AI scan alert Summary
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/7 The input-controlled signed height is used as a divisor without a zero check. A malformed image with height == 0 terminates the process with a divide-by-zero fault.
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/51 img.height is read directly from the input file and used as a divisor without a zero check, causing SIGFPE (denial of service) for a crafted file.
Damn_Vulnerable_C_Program CWE-476 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/64 main dereferences argv[1] without checking argc, resulting in a NULL pointer being passed to fopen.
Damn_Vulnerable_C_Program CWE-476 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/62 main passes argv[1] to ProcessImage without checking argc, dereferencing a NULL pointer when no argument is supplied.
Damn_Vulnerable_C_Program CWE-476 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/63 main dereferences argv[1] without checking argc, passing NULL to ProcessImage/fopen when invoked without arguments.
Damn_Vulnerable_C_Program CWE-476 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/59 main dereferences argv[1] without verifying argc >= 2; running the program without arguments passes a NULL pointer into ProcessImage, which then calls fopen(NULL, "r").
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/57 img.height, read from the input file, is used as a divisor without a zero check, causing SIGFPE.
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/54 img.height comes straight from the input file and is used as a divisor without validation, allowing a crafted file to trigger SIGFPE.
juliet-test-suite-c CWE-369 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/37 bad() reads an integer from a network socket via recv()/atoi() and then evaluates 100 / data without checking for zero. A remote peer that sends "0" (or non-numeric data, which atoi converts to 0) causes a division-by-zero and process crash (denial of service).
Broken-Vulnerable-Code-Snippets CWE-369 medium https://github.com/codeql-forks-felickz/Broken-Vulnerable-Code-Snippets/security/code-scanning/114 Image height is read from the input file and used as a divisor without checking for zero. A crafted image with zero height terminates the pr
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/70 img->height is taken from attacker-controlled input and used as a divisor with no zero check, causing a divide-by-zero fault.
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/71 img.height is read from the input file and used as a divisor without a zero check, causing a divide-by-zero crash for a crafted file.
Damn_Vulnerable_C_Program CWE-369 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/69 img.height is read from the input file and used as a divisor without a zero check, allowing a divide-by-zero crash.
juliet-test-suite-c CWE-476 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/79 The bad executable explicitly sets a character pointer to NULL and then reads its first element. Running the target causes undefined behavio
Damn_Vulnerable_C_Program CWE-571 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/66 size4 is defined as size3 + 100, so size4 > size3 is always true (barring signed overflow, which is UB). The condition therefore always takes the error branch and the else block containing buff4[size4] is dead code — the intended bounds check is not meaningful and masks the fact that the original heap out-of-bounds access logic was never correctly validated.
juliet-test-suite-c CWE-476 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/38 bad() dereferences the result of malloc() at line 25 (*intPointer = 5) before checking the pointer against NULL at line 28. If the allocation fails, the program dereferences a NULL pointer and crashes; the later NULL check is also dead code that can be removed by the optimizer.
Damn_Vulnerable_C_Program CWE-457 low https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/72 buff3 is declared without initialization and then read at index size3 before any value is stored in it, so the program consumes uninitialize
Damn_Vulnerable_C_Program CWE-252 medium https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/56 The return value of read() is not checked for -1. On error valread is negative and is passed as the size_t size parameter of ProcessImage, where it becomes a huge unsigned value that passes the size<=12 guard, allowing parsing of uninitialised stack data.
juliet-test-suite-c CWE-252 medium https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/64 bad() calls ImpersonateSelf(SecurityImpersonation) and ignores its return value. If the impersonation fails, execution continues under the original (possibly privileged) security context while the code assumes a restricted token is in effect, which can lead to privilege escalation.

Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.

Handling decision

  • Type: Query Create
  • Decision: Create a new CodeQL query. No existing query covers these patterns (most findings are gap type query-absent or missing-query). Because coverage of lower-severity patterns can be heuristic, target Community Packs unless precision is shown to be high enough for github/codeql.
  • Recommended actions across the findings: write-new-query (14), extend-existing-query (3), add-data-extension (2)

Patterns in this gap

  • divide-by-zero-tainted (4 findings), for example Damn_Vulnerable_C_Program imgRead.c
  • argv-access-without-argc-check (4 findings), for example Damn_Vulnerable_C_Program libAFL/damn_vulnerable_c_program_git/imgRead.c
  • divide-by-zero (4 findings), for example Broken-Vulnerable-Code-Snippets Out of Bounds/damnvuln.c
  • missing-query (1 finding), for example Damn_Vulnerable_C_Program dvcp.c
  • null-dereference (1 finding), for example juliet-test-suite-c testcases/CWE476_NULL_Pointer_Dereference/CWE476_NULL_Pointer_Dereference__char_01.c
  • always-true-comparison-derived-var (1 finding), for example Damn_Vulnerable_C_Program dvcp_patched.c
  • null-deref-malloc-before-check (1 finding), for example juliet-test-suite-c testcases/CWE476_NULL_Pointer_Dereference/CWE476_NULL_Pointer_Dereference__null_check_after_deref_01.c
  • uninitialized-array-read (1 finding), for example Damn_Vulnerable_C_Program dvcp_patched.c
  • unchecked-return-posix-io (1 finding), for example Damn_Vulnerable_C_Program linux/imgRead_socket.c
  • unchecked-return-win32-security (1 finding), for example juliet-test-suite-c testcases/CWE252_Unchecked_Return_Value/CWE252_Unchecked_Return_Value__w32ImpersonateSelf_01.c

Finding details

Each finding below has its own context so the agent can work from this issue alone.

1. Damn_Vulnerable_C_Program dvcp.c:82 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/7
  • AI Scan message: The input-controlled signed height is used as a divisor without a zero check. A malformed image with height == 0 terminates the process with a divide-by-zero fault.
  • Why CodeQL appears to miss it: missing-query: No installed C/C++ security query covers unchecked attacker-controlled division. A focused rule is feasible, but treating every unchecked divisor as security-sensitive would reduce precision.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
2. Damn_Vulnerable_C_Program imgRead.c:82 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/51
  • AI Scan message: img.height is read directly from the input file and used as a divisor without a zero check, causing SIGFPE (denial of service) for a crafted file.
  • Why CodeQL appears to miss it: missing-source-file-read-no-zero-check: 369 pattern: img.height is read directly from the input file and used as a divisor without a zero check, causing SIGFPE (denial of service) for a crafted file.
  • Existing CodeQL queries considered: cpp/divide-by-zero
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
3. Damn_Vulnerable_C_Program libAFL/damn_vulnerable_c_program_git/imgRead.c:112 (CWE-476, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/64
  • AI Scan message: main dereferences argv[1] without checking argc, resulting in a NULL pointer being passed to fopen.
  • Why CodeQL appears to miss it: query-absent-argv-without-argc-check: 476 pattern: main dereferences argv[1] without checking argc, resulting in a NULL pointer being passed to fopen.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
4. Damn_Vulnerable_C_Program libAFL/damn_vulnerable_c_program_shmem/imgRead_replication.c:128 (CWE-476, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/62
  • AI Scan message: main passes argv[1] to ProcessImage without checking argc, dereferencing a NULL pointer when no argument is supplied.
  • Why CodeQL appears to miss it: query-absent-argv-without-argc-check: 476 pattern: main passes argv[1] to ProcessImage without checking argc, dereferencing a NULL pointer when no argument is supplied.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
5. Damn_Vulnerable_C_Program libAFL/libafl_forkserver_fuzzer/imgRead.c:112 (CWE-476, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/63
  • AI Scan message: main dereferences argv[1] without checking argc, passing NULL to ProcessImage/fopen when invoked without arguments.
  • Why CodeQL appears to miss it: query-absent-argv-without-argc-check: 476 pattern: main dereferences argv[1] without checking argc, passing NULL to ProcessImage/fopen when invoked without arguments.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
6. Damn_Vulnerable_C_Program linux/Damn_Vulnerable_C_lib/imgRead.c:5 (CWE-476, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/59
  • AI Scan message: main dereferences argv[1] without verifying argc >= 2; running the program without arguments passes a NULL pointer into ProcessImage, which then calls fopen(NULL, "r").
  • Why CodeQL appears to miss it: query-absent-argv-without-argc-check: 476 pattern: main dereferences argv[1] without verifying argc >= 2; running the program without arguments passes a NULL pointer into ProcessImage, which then calls fopen(NULL, "r").
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
7. Damn_Vulnerable_C_Program linux/Damn_Vulnerable_C_lib/imgReadlib.c:82 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/57
  • AI Scan message: img.height, read from the input file, is used as a divisor without a zero check, causing SIGFPE.
  • Why CodeQL appears to miss it: missing-source-file-read-no-zero-check: 369 pattern: img.height, read from the input file, is used as a divisor without a zero check, causing SIGFPE.
  • Existing CodeQL queries considered: cpp/divide-by-zero
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
8. Damn_Vulnerable_C_Program linux/imgRead.c:82 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/54
  • AI Scan message: img.height comes straight from the input file and is used as a divisor without validation, allowing a crafted file to trigger SIGFPE.
  • Why CodeQL appears to miss it: missing-source-file-read-no-zero-check: 369 pattern: img.height comes straight from the input file and is used as a divisor without validation, allowing a crafted file to trigger SIGFPE.
  • Existing CodeQL queries considered: cpp/divide-by-zero
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
9. juliet-test-suite-c testcases/CWE369_Divide_by_Zero/s01/CWE369_Divide_by_Zero__int_connect_socket_divide_01.c:106 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/37
  • AI Scan message: bad() reads an integer from a network socket via recv()/atoi() and then evaluates 100 / data without checking for zero. A remote peer that sends "0" (or non-numeric data, which atoi converts to 0) causes a division-by-zero and process crash (denial of service).
  • Why CodeQL appears to miss it: missing-source-socket-recv-atoi: 369 pattern: bad() reads an integer from a network socket via recv()/atoi() and then evaluates 100 / data without checking for zero. A remote peer that sends "0" (or non-numeric data, which atoi converts to 0) causes a division-by-zero and process crash (denial of service)
  • Existing CodeQL queries considered: cpp/divide-by-zero
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
10. Broken-Vulnerable-Code-Snippets Out of Bounds/damnvuln.c:55 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Broken-Vulnerable-Code-Snippets/security/code-scanning/114
  • AI Scan message: Image height is read from the input file and used as a divisor without checking for zero. A crafted image with zero height terminates the pr
  • Context for the agent: damnvuln.c:55 divides by an image height read from the input file with no zero check. CodeQL would need a query tracking file-read values to division or modulo divisors without a dominating zero guard.
  • Why CodeQL appears to miss it: query-absent: Division by an unchecked input-derived value (CWE-369); no C/C++ security query for tainted divisors and no candidate issue covers it.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
11. Damn_Vulnerable_C_Program libAFL/damn_vulnerable_c_program_shmem/imgRead.c:74 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/70
  • AI Scan message: img->height is taken from attacker-controlled input and used as a divisor with no zero check, causing a divide-by-zero fault.
  • Context for the agent: imgRead.c:74 divides by an image height taken from input with no zero check. CodeQL would need a query tracking file-read values to divisors lacking a dominating zero guard.
  • Why CodeQL appears to miss it: query-absent: Division by an unchecked file-derived height (CWE-369); no C/C++ query for tainted divisors and no candidate issue covers it.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
12. Damn_Vulnerable_C_Program libAFL/damn_vulnerable_c_program_shmem/imgRead_replication.c:82 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/71
  • AI Scan message: img.height is read from the input file and used as a divisor without a zero check, causing a divide-by-zero crash for a crafted file.
  • Context for the agent: Image dimension read from an untrusted input file is used as a divisor with no zero check, so a crafted file crashes the program. A query tracing file or network read data to a division or modulo operand without an intervening zero guard (CWE-369) is needed; no such cpp query exists.
  • Why CodeQL appears to miss it: query-absent: No CodeQL cpp query reports divide by zero from tainted input.
  • Recommended action from the comparison: write-new-query (classification confidence: high)
13. Damn_Vulnerable_C_Program libAFL/libafl_forkserver_fuzzer/imgRead.c:76 (CWE-369, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/69
  • AI Scan message: img.height is read from the input file and used as a divisor without a zero check, allowing a divide-by-zero crash.
  • Context for the agent: Image dimension read from an untrusted input file is used as a divisor with no zero check, so a crafted file crashes the program. A query tracing file or network read data to a division or modulo operand without an intervening zero guard (CWE-369) is needed; no such cpp query exists.
  • Why CodeQL appears to miss it: query-absent: No CodeQL cpp query reports divide by zero from tainted input.
  • Recommended action from the comparison: write-new-query (classification confidence: high)
14. juliet-test-suite-c testcases/CWE476_NULL_Pointer_Dereference/CWE476_NULL_Pointer_Dereference__char_01.c:31 (CWE-476, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/79
  • AI Scan message: The bad executable explicitly sets a character pointer to NULL and then reads its first element. Running the target causes undefined behavio
  • Context for the agent: A char pointer is set to NULL and its first element is read straight after. CodeQL would need a local null-flow to dereference query.
  • Why CodeQL appears to miss it: query-absent: Pointer explicitly assigned NULL then dereferenced is a trivial null dereference not covered by a default query.
  • Existing CodeQL queries considered: cpp/redundant-null-check-simple
  • Recommended action from the comparison: write-new-query (classification confidence: low)
15. Damn_Vulnerable_C_Program dvcp_patched.c:147 (CWE-571, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/66
  • AI Scan message: size4 is defined as size3 + 100, so size4 > size3 is always true (barring signed overflow, which is UB). The condition therefore always takes the error branch and the else block containing buff4[size4] is dead code — the intended bounds check is not meaningful and masks the fact that the original heap out-of-bounds access logic was never correctly validated.
  • Why CodeQL appears to miss it: logic-flaw-not-dataflow: 571 pattern: size4 is defined as size3 + 100, so size4 > size3 is always true (barring signed overflow, which is UB). The condition therefore always takes the error branch and the else block containing buff4[size4] is dead code — the intended bounds check is not
  • Existing CodeQL queries considered: cpp/constant-comparison
  • Recommended action from the comparison: extend-existing-query (classification confidence: low)
16. juliet-test-suite-c testcases/CWE476_NULL_Pointer_Dereference/CWE476_NULL_Pointer_Dereference__null_check_after_deref_01.c:25 (CWE-476, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/38
  • AI Scan message: bad() dereferences the result of malloc() at line 25 (*intPointer = 5) before checking the pointer against NULL at line 28. If the allocation fails, the program dereferences a NULL pointer and crashes; the later NULL check is also dead code that can be removed by the optimizer.
  • Why CodeQL appears to miss it: scope-condition-malloc-deref-before-check: 476 pattern: bad() dereferences the result of malloc() at line 25 (*intPointer = 5) before checking the pointer against NULL at line 28. If the allocation fails, the program dereferences a NULL pointer and crashes; the later NULL check is also dead code that can be removed
  • Existing CodeQL queries considered: cpp/missing-null-test, cpp/dereference-before-null-check
  • Recommended action from the comparison: extend-existing-query (classification confidence: medium)
17. Damn_Vulnerable_C_Program dvcp_patched.c:142 (CWE-457, low)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/72
  • AI Scan message: buff3 is declared without initialization and then read at index size3 before any value is stored in it, so the program consumes uninitialize
  • Context for the agent: dvcp_patched.c:142 declares a local array without initialization and reads an element at an input-derived index before any store. CodeQL's uninitialized-local query would need to handle array elements accessed by non-constant index.
  • Why CodeQL appears to miss it: scope-condition: Read of an uninitialized local array element (CWE-457); cpp/uninitialized-local exists but does not cover array element reads, and no candidate issue covers uninitialized memory.
  • Existing CodeQL queries considered: cpp/uninitialized-local
  • Recommended action from the comparison: extend-existing-query (classification confidence: low)
18. Damn_Vulnerable_C_Program linux/imgRead_socket.c:74 (CWE-252, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Damn_Vulnerable_C_Program/security/code-scanning/56
  • AI Scan message: The return value of read() is not checked for -1. On error valread is negative and is passed as the size_t size parameter of ProcessImage, where it becomes a huge unsigned value that passes the size<=12 guard, allowing parsing of uninitialised stack data.
  • Why CodeQL appears to miss it: missing-function-model-read: 252 pattern: The return value of read() is not checked for -1. On error valread is negative and is passed as the size_t size parameter of ProcessImage, where it becomes a huge unsigned value that passes the size<=12 guard, allowing parsing of uninitialised stack
  • Existing CodeQL queries considered: cpp/unchecked-return-value
  • Recommended action from the comparison: add-data-extension (classification confidence: medium)
19. juliet-test-suite-c testcases/CWE252_Unchecked_Return_Value/CWE252_Unchecked_Return_Value__w32ImpersonateSelf_01.c:26 (CWE-252, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juliet-test-suite-c/security/code-scanning/64
  • AI Scan message: bad() calls ImpersonateSelf(SecurityImpersonation) and ignores its return value. If the impersonation fails, execution continues under the original (possibly privileged) security context while the code assumes a restricted token is in effect, which can lead to privilege escalation.
  • Why CodeQL appears to miss it: missing-function-model-impersonation: 252 pattern: bad() calls ImpersonateSelf(SecurityImpersonation) and ignores its return value. If the impersonation fails, execution continues under the original (possibly privileged) security context while the code assumes a restricted token is in effect, which can lead to
  • Existing CodeQL queries considered: cpp/unchecked-return-value
  • Recommended action from the comparison: add-data-extension (classification confidence: medium)

Expected Severity

Medium

Code Examples

See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.

CWE/CVE Reference (Optional)

CWE-252, CWE-369, CWE-457, CWE-476, CWE-571

References (Optional)

https://cwe.mitre.org/data/definitions/252.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    severity:medium
    on Oct 31, 2026
  2. added
    precision:medium
    tags:experimental
    on Nov 3, 2026
  3. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:medium Relies on heuristics or accepted over-approximation. Community Packs, always tags:experimental. tags:experimental Goes to Community Packs: performance, false-positive or synthetic-only concerns.

    Community Packs, experimental. Recommended for the Community Packs repository, not github/codeql. The issue is labeled tags:experimental for this.

    Linked pull request: #305

    Why. Three unrelated queries with no stock equivalent. Only the privilege-change return check is exact (an API list plus a discarded-result test). The tainted divisor query reuses a whole-struct field taint step and treats any comparison as validation, and the argv check recognizes argc validation syntactically, so both are medium and mostly crash-only findings. Community Packs, tiered by the weakest part.

    Change New query
    Target Three new C/C++ queries: argv without argc check, tainted divisor without zero check, unchecked privilege-change return
    Precision assessed medium (declared high in the pull request). Unchecked-privilege-change is an exact API list (high); tainted-divisor is flow based with a struct-field step and an 'any comparison validates' barrier (medium); argv-without-argc relies on syntactic argc check recognition (medium). Lowest governs.
    Real-world basis general. POSIX setuid family and Win32 Impersonate*/RevertToSelf APIs, argv in main, and integer division of file or network input; none depend on synthetic-app names.
    Stock overlap none. No equivalent in local stock cpp-queries 1.8.3 (grep); only experimental DivideByZeroUsingReturnValue.ql and PrivilegeDroppingOutoforder.ql are nearby but cover different patterns.
    Concerns, overlap and next steps

    False-positive concerns

    • argc validated through a stored copy, an unrecognized helper, or by testing argv[1] against NULL is still reported.
    • Divisors validated by a helper function, or made non-zero by earlier logic, are reported.
    • Explicit (void) casts of setuid or Impersonate* results, and cleanup-path calls, are reported.

    Performance concerns

    • mayTerminate is an unbounded recursive closure over the call graph.
    • Divisor query adds a field-read step and a dominance-based overwrite check per field access, with flow from all FlowSources.

    Heuristics used

    • Any comparison or truthiness test of the divisor counts as validation
    • argc passed to any dominating call counts as validating argv access
    • Hard-coded privilege-changing API name list

    What an upstream change would look like. Community Packs: three separate queries under cpp/src/security/ (CWE-252, CWE-369, CWE-476) with tests under cpp/test. The privilege-change query is the strongest candidate; argv and divisor are audit-style.

    Before opening an upstream pull request

    • Split into three PRs; precision and value differ.
    • Validate each query on real C projects and record a true positive.
    • For the argv query, handle argv[1] NULL tests and argc copies, or label it an audit query.
    • Decide whether explicit (void) casts of privilege-change calls should be exempt.

    Split note. UncheckedPrivilegeChangeReturn is high and exact; TaintedDivisorWithoutZeroCheck and ArgvAccessWithoutArgcCheck are medium and audit-like (crash-only impact). The PR is tiered by the lowest part.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-252CWE-369CWE-457CWE-476CWE-571enhancementprecision:mediumquery-createseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions