Skip to content

Commit 98034aa

Browse files
authored
Merge pull request github#2988 from asger-semmle/js/autoformat-again-again
Approved by esbena
2 parents c6e3d8d + 5356945 commit 98034aa

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

javascript/ql/src/Declarations/UnreachableMethodOverloads.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ predicate signaturesMatch(MethodSignature method, MethodSignature other) {
105105
not exists(method.getBody().getThisTypeAnnotation()) and
106106
not exists(other.getBody().getThisTypeAnnotation())
107107
or
108-
method.getBody().getThisTypeAnnotation().getType() = other.getBody().getThisTypeAnnotation().getType()
108+
method.getBody().getThisTypeAnnotation().getType() =
109+
other.getBody().getThisTypeAnnotation().getType()
109110
) and
110111
// The types are compared in matchingCallSignature. This is sanity-check that the textual representation of the type-annotations are somewhat similar.
111112
forall(int i | i in [0 .. -1 + method.getBody().getNumParameter()] |

javascript/ql/src/semmle/javascript/StringOps.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module StringOps {
6767
inner.getEnclosingExpr() = callee.getAReturnedExpr() and
6868
this.getACallee() = callee and
6969
count(this.getACallee()) = 1 and
70-
count(callee.getAReturnedExpr()) = 1 and
70+
count(callee.getAReturnedExpr()) = 1 and
7171
not this.isImprecise() and
7272
inner.getBaseString().getALocalSource().getEnclosingExpr() = callee.getAParameter() and
7373
inner.getSubstring().getALocalSource().getEnclosingExpr() = callee.getAParameter()
@@ -298,7 +298,7 @@ module StringOps {
298298
inner.getEnclosingExpr() = callee.getAReturnedExpr() and
299299
this.getACallee() = callee and
300300
count(this.getACallee()) = 1 and
301-
count(callee.getAReturnedExpr()) = 1 and
301+
count(callee.getAReturnedExpr()) = 1 and
302302
not this.isImprecise() and
303303
inner.getBaseString().getALocalSource().getEnclosingExpr() = callee.getAParameter() and
304304
inner.getSubstring().getALocalSource().getEnclosingExpr() = callee.getAParameter()
@@ -321,7 +321,6 @@ module StringOps {
321321
override boolean getPolarity() { result = inner.getPolarity() }
322322
}
323323

324-
325324
/**
326325
* A call of form `A.endsWith(B)`.
327326
*/

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,19 @@ module NodeJSLib {
633633
result = getArgument(1)
634634
}
635635

636-
override predicate isSync() {
637-
"Sync" = methodName.suffix(methodName.length() - 4)
638-
}
636+
override predicate isSync() { "Sync" = methodName.suffix(methodName.length() - 4) }
639637

640638
override DataFlow::Node getOptionsArg() {
641639
not result.getALocalSource() instanceof DataFlow::FunctionNode and // looks like callback
642640
not result.getALocalSource() instanceof DataFlow::ArrayCreationNode and // looks like argumentlist
643641
not result = getArgument(0) and
644642
// fork/spawn and all sync methos always has options as the last argument
645-
if methodName.regexpMatch("fork.*") or methodName.regexpMatch("spawn.*") or methodName.regexpMatch(".*Sync") then
646-
result = getLastArgument()
647-
else
643+
if
644+
methodName.regexpMatch("fork.*") or
645+
methodName.regexpMatch("spawn.*") or
646+
methodName.regexpMatch(".*Sync")
647+
then result = getLastArgument()
648+
else
648649
// the rest (exec/execFile) has the options argument as their second last.
649650
result = getArgument(this.getNumArgument() - 2)
650651
}

javascript/ql/src/semmle/javascript/frameworks/ShellJS.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ module ShellJS {
161161

162162
override predicate isShellInterpreted(DataFlow::Node arg) { arg = getACommandArgument() }
163163

164-
override predicate isSync() {none ()}
164+
override predicate isSync() { none() }
165165

166166
override DataFlow::Node getOptionsArg() {
167167
result = getLastArgument() and

javascript/ql/src/semmle/javascript/security/UselessUseOfCat.qll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ private class CommandCall extends DataFlow::InvokeNode {
2323
/**
2424
* Gets a list that specifies the arguments given to the command.
2525
*/
26-
DataFlow::ArrayCreationNode getArgumentList() { result = command.getArgumentList().getALocalSource() }
26+
DataFlow::ArrayCreationNode getArgumentList() {
27+
result = command.getArgumentList().getALocalSource()
28+
}
2729

2830
/**
2931
* Gets the callback (if it exists) for an async `exec`-like call.
@@ -75,8 +77,8 @@ private class CommandCall extends DataFlow::InvokeNode {
7577
}
7678

7779
/**
78-
* Holds if the input `str` contains some character that might be interpreted in a non-trivial way by a shell.
79-
*/
80+
* Holds if the input `str` contains some character that might be interpreted in a non-trivial way by a shell.
81+
*/
8082
bindingset[str]
8183
private predicate containsNonTrivialShellChar(string str) {
8284
exists(str.regexpFind("\\*|\\||>|<| |\\$|&|,|\\`| |;", _, _))
@@ -142,9 +144,7 @@ class UselessCat extends CommandCall {
142144
/**
143145
* Gets a string used to call `cat`.
144146
*/
145-
private string getACatExecuteable() {
146-
result = "cat" or result = "/bin/cat"
147-
}
147+
private string getACatExecuteable() { result = "cat" or result = "/bin/cat" }
148148

149149
/**
150150
* Predicates for creating an equivalent call to `fs.readFile` from a command execution of `cat`.
@@ -173,11 +173,10 @@ module PrettyPrintCatCall {
173173
callback = "" and not exists(cat.getCallback())
174174
) and
175175
fileArg = createFileArgument(cat).trim() and
176-
// sanity check in case of surprising `toString` results, other uses of `containsNonTrivialBashChar` should ensure that this conjunct will hold most of the time
177-
not(containsNonTrivialShellChar(fileArg.regexpReplaceAll("\\$|\\`| ", ""))) // string concat might contain " ", template strings might contain "$" or `, and that is OK.
176+
// sanity check in case of surprising `toString` results, other uses of `containsNonTrivialBashChar` should ensure that this conjunct will hold most of the time
177+
not containsNonTrivialShellChar(fileArg.regexpReplaceAll("\\$|\\`| ", "")) // string concat might contain " ", template strings might contain "$" or `, and that is OK.
178178
|
179-
result =
180-
"fs.readFile" + sync + "(" + fileArg + extraArg + callback + ")"
179+
result = "fs.readFile" + sync + "(" + fileArg + extraArg + callback + ")"
181180
)
182181
}
183182

javascript/ql/test/query-tests/Security/CWE-078/UselessUseOfCat.ql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ select msg, comment
1919

2020
query string readFile(UselessCat cat) { result = PrettyPrintCatCall::createReadFileCall(cat) }
2121

22-
query SystemCommandExecution syncCommand() {
23-
result.isSync()
24-
}
22+
query SystemCommandExecution syncCommand() { result.isSync() }
2523

26-
query DataFlow::Node options(SystemCommandExecution sys) {
27-
result = sys.getOptionsArg()
28-
}
24+
query DataFlow::Node options(SystemCommandExecution sys) { result = sys.getOptionsArg() }

0 commit comments

Comments
 (0)