Skip to content

Commit 5c3f21b

Browse files
authored
Merge pull request github#18937 from hvitved/rust/fix-bad-joins
Rust: Fix bad joins
2 parents da579c2 + ec063d0 commit 5c3f21b

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessConstructor.qll

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ predicate constructFormatTemplateVariableAccess(Raw::FormatArgsExpr parent, int
1717
unboundNamedFormatArgument(parent, index, kind, _)
1818
}
1919

20-
/**
21-
* A named format argument for which no binding is found in the parent `FormatArgsExpr::getArg(_)`.
22-
* INTERNAL: Do not use.
23-
*/
24-
predicate unboundNamedFormatArgument(
25-
Raw::FormatArgsExpr parent, int index, int kind, NamedFormatArgument arg
20+
pragma[nomagic]
21+
private predicate formatArgsHasArg(
22+
Raw::FormatArgsExpr parent, NamedFormatArgument arg, string name, int index, int kind
2623
) {
27-
exists(Format format, string name |
28-
not parent.getArg(_).getName().getText() = name and
24+
exists(Format format |
25+
parent = Synth::convertFormatArgsExprToRaw(format.getParent()) and
2926
name = arg.getName() and
30-
Synth::convertFormatArgsExprToRaw(format.getParent()) = parent and
3127
format.getIndex() = index
3228
|
3329
arg = format.getArgumentRef() and kind = 0
@@ -37,3 +33,21 @@ predicate unboundNamedFormatArgument(
3733
arg = format.getPrecisionArgument() and kind = 2
3834
)
3935
}
36+
37+
pragma[nomagic]
38+
private predicate formatArgsHasArgName(Raw::FormatArgsExpr parent, string name) {
39+
parent.getArg(_).getName().getText() = name
40+
}
41+
42+
/**
43+
* A named format argument for which no binding is found in the parent `FormatArgsExpr::getArg(_)`.
44+
* INTERNAL: Do not use.
45+
*/
46+
predicate unboundNamedFormatArgument(
47+
Raw::FormatArgsExpr parent, int index, int kind, NamedFormatArgument arg
48+
) {
49+
exists(string name |
50+
formatArgsHasArg(parent, arg, name, index, kind) and
51+
not formatArgsHasArgName(parent, name)
52+
)
53+
}

0 commit comments

Comments
 (0)