Skip to content

Commit bee2dda

Browse files
committed
C++: Fix all prepareQueries errors and warnings
With these changes we can run `odasa prepareQueries --check-only --fail-on-warnings` on the C++ query directory. Two changes were needed: 1. The `Metrics/queries.xml` file had to be deleted. It existed because the built distribution has a different file layout, where `Metrics` is moved to the top-level query dir `odasa-cpp-metrics`. Since internal PR 28230 this file is created as needed as part of the dist build process, so it doesn't need to be checked in with the sources. 2. All uses of the `deprecated` and stubbed-out Objective C classes were removed.
1 parent a4b3b1e commit bee2dda

File tree

5 files changed

+1
-106
lines changed

5 files changed

+1
-106
lines changed

cpp/ql/src/Metrics/queries.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/ql/src/semmle/code/cpp/commons/Environment.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,5 @@ private predicate readsEnvironment(Expr read, string sourceDescription) {
3434
read = call and
3535
call.getTarget().hasGlobalName(name) and
3636
(name = "getenv" or name = "secure_getenv" or name = "_wgetenv") and
37-
sourceDescription = name) or
38-
exists(MessageExpr getObjectKey, MessageExpr getEnviron |
39-
read = getObjectKey and
40-
getObjectKey.getTarget().getQualifiedName().matches("NSDictionary%::-objectForKey:") and
41-
getObjectKey.getQualifier() = getEnviron and
42-
getEnviron.getTarget().getQualifiedName().matches("NSProcessInfo%:-environment") and
43-
sourceDescription = "NSProcessInfo")
37+
sourceDescription = name)
4438
}

cpp/ql/src/semmle/code/cpp/security/CommandExecution.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,5 @@ predicate shellCommand(Expr command, string callChain) {
203203
and arrayInitializer.getChild(idx) = command
204204
and shellCommandPreface(commandInterpreter.getValue(), flag.getValue())
205205
and idx > 1)
206-
207-
// Creation of NSTask
208-
or exists(
209-
MessageExpr launchedTaskCall, TextLiteral commandInterpreter,
210-
Expr arrayLiteral, TextLiteral flag
211-
|
212-
launchedTaskCall.getStaticTarget().getQualifiedName().matches("NSTask%::+launchedTaskWithLaunchPath:arguments:")
213-
and commandInterpreter = launchedTaskCall.getArgument(0)
214-
and arrayLiteral = launchedTaskCall.getArgument(1)
215-
and arrayElement(arrayLiteral, 0, flag)
216-
and arrayElement(arrayLiteral, 1, command)
217-
and shellCommandPreface(commandInterpreter.getValue(), flag.getValue())
218-
and callChain = "NSTask")
219206
}
220207

cpp/ql/src/semmle/code/cpp/security/SensitiveExprs.qll

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,3 @@ class SensitiveCall extends SensitiveExpr {
3535
)
3636
}
3737
}
38-
39-
class SensitivePropAccess extends SensitiveExpr {
40-
SensitivePropAccess() {
41-
exists (PropertyAccess acc, string name |
42-
acc = this and
43-
name = acc.getProperty().getName().toLowerCase() and
44-
name.matches(suspicious()) and
45-
not name.matches(nonSuspicious()))
46-
}
47-
}
48-
49-
/**
50-
* A read from the value of a text widget.
51-
*/
52-
class SensitiveTextRead extends SensitiveExpr {
53-
SensitiveTextRead() {
54-
exists (PropertyAccess facc |
55-
facc = this and
56-
facc.getReceiver() instanceof SensitiveExpr and
57-
facc.getProperty().getName() = "text")
58-
}
59-
}

cpp/ql/src/semmle/code/cpp/security/TaintTracking.qll

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,12 @@ predicate insideFunctionValueMoveTo(Element src, Element dest)
238238
returnArgument(c.getTarget(), sourceArg)
239239
and src = c.getArgument(sourceArg)
240240
and dest = c)
241-
or exists (MessageExpr send |
242-
methodReturningAnyArgument(send.getStaticTarget())
243-
and not send instanceof FormattingFunctionCall
244-
and src = send.getAnArgument()
245-
and dest = send)
246241
or exists(FormattingFunctionCall formattingSend, int arg, FormatLiteral format, string argFormat |
247242
dest = formattingSend
248243
and formattingSend.getArgument(arg) = src
249244
and format = formattingSend.getFormat()
250245
and format.getConversionChar(arg - formattingSend.getTarget().getNumberOfParameters()) = argFormat
251246
and (argFormat = "s" or argFormat = "S" or argFormat = "@"))
252-
or exists (ExprMessageExpr send |
253-
methodReturningReceiver(send.getStaticTarget())
254-
and src = send.getReceiver()
255-
and dest = send)
256247
// Expressions computed from tainted data are also tainted
257248
or (exists (FunctionCall call | dest = call and isPureFunction(call.getTarget().getName()) |
258249
call.getAnArgument() = src
@@ -457,60 +448,6 @@ private predicate returnArgument(Function f, int sourceArg)
457448
or (f.hasGlobalName("gethostbyaddr") and sourceArg = 0)
458449
}
459450

460-
/** A method where if any argument is tainted, the return value should be, too */
461-
private predicate methodReturningAnyArgument(MemberFunction method) {
462-
method.getQualifiedName().matches("NS%Array%::+array%") or
463-
method.getQualifiedName().matches("NS%Array%::-arrayBy%") or
464-
method.getQualifiedName().matches("NS%Array%::-componentsJoinedByString:") or
465-
method.getQualifiedName().matches("NS%Array%::-init%") or
466-
method.getQualifiedName().matches("NS%Data%::+dataWith%") or
467-
method.getQualifiedName().matches("NS%Data%::-initWith%") or
468-
method.getQualifiedName().matches("NS%String%::+pathWithComponents:") or
469-
method.getQualifiedName().matches("NS%String%::+stringWith%") or
470-
method.getQualifiedName().matches("NS%String%::-initWithCString:") or
471-
method.getQualifiedName().matches("NS%String%::-initWithCString:length:") or
472-
method.getQualifiedName().matches("NS%String%::-initWithCStringNoCopy:length:") or
473-
method.getQualifiedName().matches("NS%String%::-initWithCharacters:length:") or
474-
method.getQualifiedName().matches("NS%String%::-initWithCharactersNoCopy:length:freeWhenDone:") or
475-
method.getQualifiedName().matches("NS%String%::-initWithFormat:") or
476-
method.getQualifiedName().matches("NS%String%::-initWithFormat:arguments:") or
477-
method.getQualifiedName().matches("NS%String%::-initWithString:") or
478-
method.getQualifiedName().matches("NS%String%::-initWithUTF8String:") or
479-
method.getQualifiedName().matches("NS%String%::-stringByAppendingFormat:") or
480-
method.getQualifiedName().matches("NS%String%::-stringByAppendingString:") or
481-
method.getQualifiedName().matches("NS%String%::-stringByPaddingToLength:withString:startingAtIndex:") or
482-
method.getQualifiedName().matches("NS%String%::-stringByReplacing%") or
483-
method.getQualifiedName().matches("NS%String%::-stringsByAppendingPaths:")
484-
}
485-
486-
/** A method where if the receiver is tainted, the return value should be, too */
487-
private predicate methodReturningReceiver(MemberFunction method) {
488-
method.getQualifiedName().matches("NS%Array%::-arrayBy%") or
489-
method.getQualifiedName().matches("NS%Array%::-componentsJoinedByString:") or
490-
method.getQualifiedName().matches("NS%Array%::-firstObject") or
491-
method.getQualifiedName().matches("NS%Array%::-lastObject") or
492-
method.getQualifiedName().matches("NS%Array%::-objectAt%") or
493-
method.getQualifiedName().matches("NS%Array%::-pathsMatchingExtensions:") or
494-
method.getQualifiedName().matches("NS%Array%::-sortedArray%") or
495-
method.getQualifiedName().matches("NS%Array%::-subarrayWithRange:") or
496-
method.getQualifiedName().matches("NS%Data%::-bytes") or
497-
method.getQualifiedName().matches("NS%Data%::-subdataWithRange:") or
498-
method.getQualifiedName().matches("NS%String%::-capitalizedString%") or
499-
method.getQualifiedName().matches("NS%String%::-componentsSeparatedByCharactersInSet:") or
500-
method.getQualifiedName().matches("NS%String%::-componentsSeparatedByString:") or
501-
method.getQualifiedName().matches("NS%String%::-cStringUsingEncoding:") or
502-
method.getQualifiedName().matches("NS%String%::-dataUsingEncoding:%") or
503-
method.getQualifiedName().matches("NS%String%::-lowercaseString%") or
504-
method.getQualifiedName().matches("NS%String%::-pathComponents") or
505-
method.getQualifiedName().matches("NS%String%::-stringBy%") or
506-
method.getQualifiedName().matches("NS%String%::-stringsByAppendingPaths:") or
507-
method.getQualifiedName().matches("NS%String%::-substringFromIndex:") or
508-
method.getQualifiedName().matches("NS%String%::-substringToIndex:") or
509-
method.getQualifiedName().matches("NS%String%::-substringWithRange:") or
510-
method.getQualifiedName().matches("NS%String%::-uppercaseString%") or
511-
method.getQualifiedName().matches("NS%String%::-UTF8String")
512-
}
513-
514451
/**
515452
* Resolve potential target function(s) for `call`.
516453
*

0 commit comments

Comments
 (0)