Commit Graph

14516 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
76e3118aba Commit 2: Fix \0 escape parsing
In ECMAScript std::regex, \0 matches NUL. The previous escapedCharacter
arms all rejected it: the final arm's `not exists(getChar(start+1).toInt())`
guard fails for "0", and the numbered-backref arm excludes 0. Add an
explicit \0 case (end=start+2) guarded so the following character is not
a digit, mirroring EcmaRegExp.escapedCharacter in PR #22200. Add corpus
case "a\\0b" to test.cpp; \0 now parses as RegExpEscape.

Bundle: github/codeql-action codeql-bundle-v2.26.1 (CodeQL CLI 2.26.1).
2026-07-21 12:18:23 +00:00
copilot-swe-agent[bot]
448ae6af53 Commit 1: Remove \p{...}/\P{...} named-character-property handling
std::regex ECMAScript mode does not support \p{Name}; \p tokenizes as an
identity escape. Remove pStyleNamedCharacterProperty and its call sites;
namedCharacterProperty now covers only POSIX brackets ([:name:], [.x.],
[=x=]) and namedCharacterPropertyIsInverted keeps only the [[:^name:]]
case (fixing the offset from start+3 to start+2 for POSIX). Update
RegExpNamedCharacterProperty getName/isInverted docs to describe POSIX
brackets. Remove the four \p{...}/\P{...} corpus lines from test.cpp;
keep a plain [a-f\d]+ case for the class-with-escape shape.

Bundle: github/codeql-action codeql-bundle-v2.26.1 (CodeQL CLI 2.26.1).
2026-07-21 12:16:37 +00:00
copilot-swe-agent[bot]
bfa65301f1 Commit 9: Fix hasLocationInfo for all string literal forms; fix unicode escape
RegexTreeView.qll - hasLocationInfo fix (RULE 4):
- Add regexpContentOffset(RegExp re) private helper that computes the correct
  number of source chars before the first content char, from getValueText():
  - Plain "...":          offset 1
  - L"...":               offset 2 (L" prefix)
  - u8"...":              offset 3 (u8" prefix)
  - R"(...)":             offset 3 (R"( opener)
  - R"x(...)x":          offset 4 (R"x( with custom delim)
  - LR"(...)":            offset 4 (LR"()
  - Uses vt.matches("%R\"%(%") to detect raw strings; finds '(' position
  - For non-raw, finds '"' position
- Replace hardcoded `+ 1` with `+ regexpContentOffset(re)` in hasLocationInfo
- Update comment: documents plain/encoding/raw/combined forms, notes that
  escaped non-raw strings are approximate (mirroring Java/Python)

test.cpp:
- Fix r_uni: change "\\u{9879}" to "\\u9879" — braced \u{...} is not standard
  C++ regex syntax; the 4-digit \uHHHH form is valid ECMAScript \u escape

Regenerated all 3 .expected files via codeql test run --learn (CodeQL 2.26.1).
All 3 tests pass.

Location test confirms:
- Plain "a+b" (line 144): litStartCol 22 → termStartCol 23 (22+1)  UNCHANGED ✓
- Raw R"(a+b)" (line 147): litStartCol 20 → termStartCol 23 (20+3)  FIXED ✓
- Raw R"x(a+b)x" (line 156): litStartCol 21 → termStartCol 25 (21+4) FIXED ✓
- L"a+b" (line 159): litStartCol 22 → termStartCol 24 (22+2)         FIXED ✓
- LR"(a+b)" (line 162): litStartCol 26 → termStartCol 30 (26+4)      FIXED ✓
2026-07-21 10:36:49 +00:00
copilot-swe-agent[bot]
e7ccb1f2ce Commit 8: Add location tests exposing term-location off-by-one (pre-fix)
Add location test cases to test.cpp covering various C++ string literal forms:
- r_plain:     "a+b"          — plain, offset 1 (already correct)
- r_raw:       R"(a+b)"       — raw, offset 3 (R"( = 3); currently uses 1 (WRONG)
- r_raw2:      R"(\s+$)"      — raw with metacharacters; currently wrong
- r_raw3:      R"(\(([,\w]+)+\)$)" — complex raw; currently wrong
- r_raw4:      R"x(a+b)x"    — custom-delimiter raw, offset 4; currently uses 1 (WRONG)
- r_wide:      L"a+b"         — L" prefix, offset 2; currently uses 1 (WRONG)
- r_wide_raw:  LR"(a+b)"      — combined LR"( prefix, offset 4; currently uses 1 (WRONG)
- r_esc1:      "\\s+"         — escape-containing plain; offset 1 (correct)
- r_esc2:      "a\\.b"        — escaped dot; offset 1 (correct)

Added std::wregex typedef to stubs (for L"..." and LR"(...)" wide-char literals).

New locations.ql query reports per-term: litStartCol, valueStart, valueEnd,
termStartCol, termEndCol — restricted to test_locations() function.

Generated locations.expected via codeql test run --learn (CodeQL 2.26.1).
All 3 tests pass. The expected output captures the CURRENT (pre-fix) columns:
raw/prefixed rows show termStartCol = litStartCol + 1 (wrong);
plain rows show litStartCol + 1 (correct).
Commit 9 changes the raw/prefixed rows to their correct values.
2026-07-21 10:27:55 +00:00
copilot-swe-agent[bot]
cebddbdd42 Commit 7: Implement POSIX collating symbol and equivalence class support
Add posixCollatingSymbol([.x.]) and posixEquivalenceClass([=x=]) predicates
to ParseRegExp.qll, enabling correct tokenization of all three POSIX bracket
atom types inside character classes:
  - [:name:]  — already handled, unchanged
  - [.x.]     — new: posixCollatingSymbol predicate
  - [=x=]     — new: posixEquivalenceClass predicate

Refactored:
- charSetDelimiter: use inAnyPosixBracket helper (covers all three types)
- charSet closing: use inAnyPosixBracket helper
- inPosixBracket: updated to cover all three types
- simpleCharacter: updated to exclude all three types
- namedCharacterProperty: includes posixCollatingSymbol and posixEquivalenceClass
- inAnyPosixBracket: new private helper; uses pos in [x..y-1] for QL binding

Before this commit (commit 6):
  [[.a.]] → RegExpCharacterClass([[.a.]) + stray ]   (WRONG)
  [[=a=]] → RegExpCharacterClass([[=a=]) + stray ]   (WRONG)

After this commit:
  [[.a.]] → RegExpCharacterClass containing RegExpNamedCharacterProperty [.a.]
  [[=a=]] → RegExpCharacterClass containing RegExpNamedCharacterProperty [=a=]

Regenerated parse.expected and regexp.expected via codeql test run --learn
(CodeQL 2.26.1); all 2 tests pass.
2026-07-21 10:22:50 +00:00
copilot-swe-agent[bot]
9fd7e949c8 Commit 6: Add POSIX-bracket extension tests (pre-fix, capturing incorrect tokenization)
Add new test cases to test.cpp exercising POSIX bracket expressions inside
character classes as supported by std::regex ECMAScript mode:
- Single POSIX classes: [[:alpha:]], [[:digit:]], [[:space:]], [[:upper:]],
  [[:lower:]], [[:alnum:]], [[:print:]], [[:punct:]]
- Negated outer bracket: [^[:space:]]
- Mixed: regular char + POSIX class [a[:space:]]
- POSIX collating symbol [[.a.]]
- POSIX equivalence class [[=a=]]
- Mixed POSIX + range [[:alpha:]0-9]

The existing r_posix1-r_posix4 cases remain untouched. New cases use distinct
names (r_posix_alpha, r_posix_digit, etc.) to avoid redeclaration.

Generated .expected via codeql test run --learn (CodeQL 2.26.1); all 2 tests
pass. The expected output captures the CURRENT (pre-fix) tokenization — commit 7
will change these rows when correct POSIX nesting is implemented.
2026-07-21 10:17:14 +00:00
copilot-swe-agent[bot]
67ff5896a8 Commit 5: Remove Ruby-only parser features; shift to ECMAScript dialect
- ParseRegExp.qll:
  - specialCharacter: remove \A, \Z, \z, \G (Ruby-only anchors); keep only \b, \B
  - firstPart: remove \A arm; keep only ^ for start-of-string
  - lastPart: remove \Z, \z arms; keep only $ for end-of-string
  - nonCapturingGroupStart: remove < from char set (handled by namedGroupStart
    and lookbehindAssertionStart; was causing mis-tokenization of lookbehind)
  - namedGroupStart: remove Ruby-only single-quote (?'name'...) branch; keep
    only ECMAScript (?<name>...) syntax
- RegexTreeView.qll:
  - RegExpCharacterClassEscape: remove h, H (Ruby hex-digit classes); keep
    d, D, s, S, w, W (ECMAScript set)
  - RegExpAnchor: change to [^, $] only (remove \A, \Z, \z)
  - RegExpDollar: change to $ only (remove \Z, \z)
  - RegExpCaret: change to ^ only (remove \A)
- test.cpp:
  - r_cc3: replace \A[+-]?\d+ with ^[+-]?\d+ (ECMAScript caret)
  - r_meta5 \h\H: removed (Ruby-only hex classes)
  - r_anc1 \Gabc: removed (\G not in ECMAScript)
- Regenerated parse.expected and regexp.expected via codeql test run --learn
  (CodeQL 2.26.1); all 2 tests pass.
2026-07-21 10:15:58 +00:00
copilot-swe-agent[bot]
96c7e2dbc5 Commit 4: Curate corpus for C++ ECMAScript; regenerate .expected
Content-only edits to test.cpp to remove Ruby-only syntax that has no
C++ ECMAScript equivalent:

1. Removed: "a{,8}" — Ruby-only "{,n}" no-lower-bound quantifier
   (ECMAScript requires an explicit lower bound in {n,m})

2. Removed: second ".*" for /.*/m — mode flags in C++ are construction-site
   arguments (e.g. std::regex::multiline), not part of the pattern string.
   This mode variant was the exact same pattern string as r_meta1 so it
   added no coverage.

3. Removed: "(?'foo'fo+)" — Ruby single-quote named-group form.
   ECMAScript only supports the angle-bracket form (?<name>...).

Left in place for now (removed with the parser in commit 5):
  \\A, \\z, \\G, \\h, \\H — Ruby-only anchor/escape classes.
  The POSIX-bracket cases are kept through commit 7.

.expected regenerated by:
  codeql test run --learn --search-path=. cpp/ql/test/library-tests/regex/
  (CodeQL CLI 2.26.1)
All 2 tests passed.
2026-07-21 10:12:21 +00:00
copilot-swe-agent[bot]
d7a8f48c1c Commit 3: Add test.cpp corpus wrapped in std::regex stubs; generate .expected
Introduces cpp/ql/test/library-tests/regex/test.cpp with the Ruby regex
corpus mechanically translated to C++ string literals and wrapped in
std::regex construction calls using fully self-contained in-file stubs
(no #include of any external/standard header).

Stub surface:
  std::basic_regex<CharT>  constructor(const char*), constructor(const char*, int),
                           assign(const char*)
  std::regex               typedef for basic_regex<char>
  std::regex_match / regex_search / regex_replace  free functions

1:1 corpus mapping from regexp.rb:
  - All Ruby /regex/ literals translated to C++ "string" literals
    (each backslash doubled: /\d/ -> "\\d")
  - Dropped: /#{A}bc/ (Ruby string interpolation, no string-literal form)
  - Kept: a{,8}, .*m, \A, \z, \G, \h\H, (?'foo'...) — these are removed
    in commits 4 and 5 (keeping them here preserves 1:1 mapping)

Also removes `abstract` from RegExp class in ParseRegExp.qll so that all
StringLiterals are regex candidates (trivial syntactic gate; no dataflow).

.expected generated by:
  codeql test run --learn --search-path=. cpp/ql/test/library-tests/regex/
  (CodeQL CLI 2.26.1, bundled C/C++ extractor)
All 2 tests passed.
2026-07-21 10:11:27 +00:00
copilot-swe-agent[bot]
52b35ef08e Commit 2: Adapt Ruby regex library to compile against C++
Changes from verbatim Ruby baseline (Commit 1) to compilable C++:

ParseRegExp.qll:
- Remove: private import codeql.ruby.AST as Ast
- Remove: private import codeql.Locations
- Add: private import semmle.code.cpp.exprs.Literal
- Change RegExp base: Ast::StringlikeLiteral -> StringLiteral
- Replace getText(): removes getConstantValue() Ruby accessor, uses getValue()
  (C++ StringLiteral.getValue() returns the string content, analogous to
   Ruby's getConstantValue().getString())

RegexTreeView.qll:
- Remove Ruby-specific imports (codeql.ruby.AST, codeql.Locations,
  codeql.regex.nfa.NfaUtils)
- Add: private import semmle.code.cpp.exprs.Literal
- Keep: codeql.util.Numbers (for parseHexInt in RegExpEscape.getUnicode())
- Keep: codeql.regex.RegexTreeView (satisfies RegexTreeViewSig)
- Change getParsedRegExp: Ast::RegExpLiteral -> StringLiteral
- Simplify hasLocationInfo to use re.getLocation() directly with +1 offset
  for opening quote (approximate; fixed in commits 8-9)
- Replace isExcluded: remove hasFreeSpacingFlag(), use none()
- Ruby dialect features preserved unchanged (\\A, \\z, \\G, \\h, etc.);
  dialect shift is commit 5

Test queries:
- parse.ql, regexp.ql: replace codeql.ruby.Regexp with
  semmle.code.cpp.regex.RegexTreeView
- .expected cleared (no test.cpp until commit 3)

Verified: both queries compile successfully with codeql query compile.
2026-07-21 10:08:22 +00:00
copilot-swe-agent[bot]
90a14d82b5 Commit 1: Copy Ruby regex library files verbatim (non-compiling checkpoint)
This is a verbatim copy of the Ruby ParseRegExp.qll and RegExpTreeView.qll,
with only the file-header comments updated to reflect the new path.
The test files (parse.ql, regexp.ql, regexp.rb, *.expected) are also copied
verbatim from the Ruby test suite as a baseline reference.

This commit does NOT compile against C++: it still imports codeql.ruby.AST
and references Ruby AST types (RegExpLiteral, StringlikeLiteral, etc.).
The adaptation to compile against C++ is in the next commit.

Also adds the codeql/regex dependency to cpp/ql/lib/qlpack.yml and the
unreleased change-note at cpp/ql/lib/change-notes/2026-07-21-cpp-regex-tree-view.md.
2026-07-21 10:01:38 +00:00
Óscar San José
87835f7f3d Merge pull request #22207 from github/codeql-spark-run-29493713448
Update changelog documentation site for codeql-cli-2.26.1
2026-07-17 12:10:28 +02:00
Jeroen Ketema
9efcc49af7 C++: Update the CWE tag of cpp/new-free-mismatch 2026-07-13 13:06:15 +02:00
github-actions[bot]
9acbbb8049 Release preparation for version 2.26.1 2026-07-09 16:48:01 +00:00
Jeroen Ketema
161c8c4d30 Merge pull request #22149 from jketema/jketema/cwe-114-tag
C++/C#: Specify additional CWE tags for queries that specify CWE 114
2026-07-09 18:02:21 +02:00
Jeroen Ketema
72efb6a058 C++: Add CWE 73 and CWE 78 tags to cpp/uncontrolled-process-operation
User controlled data here either leads to the loading of an uncontrolled
library (CWE 73) or the execution of an uncontrolled command (CWE 78).
2026-07-09 17:11:58 +02:00
Owen Mansel-Chan
19745e13b5 Fix some lines with // $ ... // $ MISSING:
Note that when a line is marked `// BAD [NOT DETECTED]` but actually has
an alert, I assume that the `[NOT DETECTED]` is outdated and should be
deleted.
2026-07-07 20:48:39 +01:00
Owen Mansel-Chan
9d9590623d Address review comments 2026-07-07 20:48:36 +01:00
Owen Mansel-Chan
fa16728522 Fix comments in one test 2026-07-07 12:06:43 +01:00
Owen Mansel-Chan
76d8ae8694 Add MISSING: tag 2026-07-07 10:59:21 +01:00
Owen Mansel-Chan
843ac7c6b0 Add SPURIOUS: tags 2026-07-07 10:54:11 +01:00
Owen Mansel-Chan
a2c5d4c818 C++: Convert qlref tests to inline expectations 2026-07-07 09:49:50 +01:00
Mathias Vorreiter Pedersen
4f4cdf434b Merge pull request #22061 from MathiasVP/mad-write-through-model
Shared: Support flow summaries from `ReturnValue`s
2026-07-02 12:38:44 +01:00
Mathias Vorreiter Pedersen
dbbcc1741c C++: Delete now-unsupported MaD rows. 2026-06-30 17:48:31 +01:00
Mathias Vorreiter Pedersen
f37b3e77ff Merge branch 'main' into remove-mad-support-for-variables 2026-06-30 17:38:37 +01:00
Mathias Vorreiter Pedersen
b7b731bab7 Merge branch 'main' into mad-write-through-model 2026-06-30 15:12:02 +01:00
Mathias Vorreiter Pedersen
06f54d1bbb C++: Add a TODO comment to remove support for unqualified field names. 2026-06-30 13:55:26 +01:00
Mathias Vorreiter Pedersen
396bea6e6a Update cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll
Co-authored-by: Tom Hvitved <hvitved@github.com>
2026-06-30 13:44:14 +01:00
Mathias Vorreiter Pedersen
0e05ea5153 C++: Remove whitespace. 2026-06-30 12:41:29 +01:00
Mathias Vorreiter Pedersen
8657c8b26e C++: Add change note. 2026-06-30 12:39:34 +01:00
Mathias Vorreiter Pedersen
449a3ac870 C++: Delete tests which are no longer relevant. 2026-06-30 12:39:31 +01:00
Mathias Vorreiter Pedersen
fc954c3e1a C++: Remove support for marking variables as sources and sinks in MaD. 2026-06-30 12:30:40 +01:00
Mathias Vorreiter Pedersen
81ed5c59d7 C++: Add change note. 2026-06-30 11:54:58 +01:00
Mathias Vorreiter Pedersen
caaed72288 C++: Hide summary nodes that should be hidden and accept test changes. 2026-06-29 18:30:03 +01:00
Mathias Vorreiter Pedersen
08c383df6a C++: Accept test changes. 2026-06-29 18:20:10 +01:00
Mathias Vorreiter Pedersen
2625c304bf C++: Support fully qualified field names in MaD. 2026-06-29 18:02:20 +01:00
Mathias Vorreiter Pedersen
49bde567dd C++: Add tests with qualified names in MaD. 2026-06-29 18:02:17 +01:00
github-actions[bot]
456e33773b Post-release preparation for codeql-cli-2.26.0 2026-06-25 16:24:06 +00:00
github-actions[bot]
237c5639e2 Release preparation for version 2.26.0 2026-06-25 15:27:00 +00:00
Mathias Vorreiter Pedersen
933338f627 C++: Accept test changes. 2026-06-23 20:33:34 +01:00
Mathias Vorreiter Pedersen
662f522032 C++: Properly instantiate the new reverse flow feature. 2026-06-23 20:33:31 +01:00
Mathias Vorreiter Pedersen
076b01cbfc C++: Fixes after changes to the flow summary API. 2026-06-23 20:33:08 +01:00
Mathias Vorreiter Pedersen
03c3ef9528 C++: Add tests with missing reverse flow. 2026-06-23 19:48:21 +01:00
Idriss Riouak
ec91865a7f Merge pull request #22030 from github/idrissrio/cpp/update-stats-file
C/C++: Update stats file
2026-06-23 10:26:52 +02:00
idrissrio
0a41157d77 C/C++: update stats file 2026-06-22 10:27:21 +02:00
Jeroen Ketema
ef00aa2567 C++: Add upgrade and downgrade scripts 2026-06-10 14:38:15 +02:00
Jeroen Ketema
6d0968744b C++: Fix NameQualifyingElement db inconsistency 2026-06-10 14:35:36 +02:00
Jeroen Ketema
98f147556a C++: Add namequalifier test with inconsistency
While where the remove the file restriction in QL.
2026-06-10 14:27:56 +02:00
Jeroen Ketema
ab4a575243 Merge pull request #21899 from MathiasVP/use-new-prototype-extensionals
C++: Use the new `prototype`-related extensionals in MaD
2026-06-01 10:24:19 +02:00
Mathias Vorreiter Pedersen
22b08f1ea4 C++: Add a test with a kind of "partial function template" instantiation. 2026-05-31 12:47:31 +02:00