Skip to content

Commit 0374f84

Browse files
committed
Java: Make support for generated as a part of kind.
1 parent 3a04e9a commit 0374f84

File tree

4 files changed

+53
-42
lines changed

4 files changed

+53
-42
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,17 @@ private predicate summaryModel(string row) {
404404
any(SummaryModelCsv s).row(row)
405405
}
406406

407+
bindingset[input]
408+
private predicate getKind(string input, string kind, boolean generated) {
409+
input.splitAt(":", 0) = "generated" and kind = input.splitAt(":", 1) and generated = true
410+
or
411+
not input.matches("%:%") and kind = input and generated = false
412+
}
413+
407414
/** Holds if a source model exists for the given parameters. */
408415
predicate sourceModel(
409416
string namespace, string type, boolean subtypes, string name, string signature, string ext,
410-
string output, string kind
417+
string output, string kind, boolean generated
411418
) {
412419
exists(string row |
413420
sourceModel(row) and
@@ -419,14 +426,14 @@ predicate sourceModel(
419426
row.splitAt(";", 4) = signature and
420427
row.splitAt(";", 5) = ext and
421428
row.splitAt(";", 6) = output and
422-
row.splitAt(";", 7) = kind
429+
exists(string k | row.splitAt(";", 7) = k and getKind(k, kind, generated))
423430
)
424431
}
425432

426433
/** Holds if a sink model exists for the given parameters. */
427434
predicate sinkModel(
428435
string namespace, string type, boolean subtypes, string name, string signature, string ext,
429-
string input, string kind
436+
string input, string kind, boolean generated
430437
) {
431438
exists(string row |
432439
sinkModel(row) and
@@ -438,22 +445,22 @@ predicate sinkModel(
438445
row.splitAt(";", 4) = signature and
439446
row.splitAt(";", 5) = ext and
440447
row.splitAt(";", 6) = input and
441-
row.splitAt(";", 7) = kind
448+
exists(string k | row.splitAt(";", 7) = k and getKind(k, kind, generated))
442449
)
443450
}
444451

445452
/** Holds if a summary model exists for the given parameters. */
446453
predicate summaryModel(
447454
string namespace, string type, boolean subtypes, string name, string signature, string ext,
448-
string input, string output, string kind
455+
string input, string output, string kind, boolean generated
449456
) {
450-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, _)
457+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated, _)
451458
}
452459

453460
/** Holds if a summary model `row` exists for the given parameters. */
454461
predicate summaryModel(
455462
string namespace, string type, boolean subtypes, string name, string signature, string ext,
456-
string input, string output, string kind, string row
463+
string input, string output, string kind, boolean generated, string row
457464
) {
458465
summaryModel(row) and
459466
row.splitAt(";", 0) = namespace and
@@ -465,13 +472,13 @@ predicate summaryModel(
465472
row.splitAt(";", 5) = ext and
466473
row.splitAt(";", 6) = input and
467474
row.splitAt(";", 7) = output and
468-
row.splitAt(";", 8) = kind
475+
exists(string k | row.splitAt(";", 8) = k and getKind(k, kind, generated))
469476
}
470477

471478
private predicate relevantPackage(string package) {
472-
sourceModel(package, _, _, _, _, _, _, _) or
473-
sinkModel(package, _, _, _, _, _, _, _) or
474-
summaryModel(package, _, _, _, _, _, _, _, _)
479+
sourceModel(package, _, _, _, _, _, _, _, _) or
480+
sinkModel(package, _, _, _, _, _, _, _, _) or
481+
summaryModel(package, _, _, _, _, _, _, _, _, _, _)
475482
}
476483

477484
private predicate packageLink(string shortpkg, string longpkg) {
@@ -499,25 +506,25 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
499506
part = "source" and
500507
n =
501508
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
502-
string ext, string output |
509+
string ext, string output, boolean generated |
503510
canonicalPkgLink(package, subpkg) and
504-
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind)
511+
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind, generated)
505512
)
506513
or
507514
part = "sink" and
508515
n =
509516
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
510-
string ext, string input |
517+
string ext, string input, boolean generated |
511518
canonicalPkgLink(package, subpkg) and
512-
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind)
519+
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind, generated)
513520
)
514521
or
515522
part = "summary" and
516523
n =
517524
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
518-
string ext, string input, string output |
525+
string ext, string input, string output, boolean generated |
519526
canonicalPkgLink(package, subpkg) and
520-
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind)
527+
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind, generated)
521528
)
522529
)
523530
}
@@ -527,11 +534,11 @@ module CsvValidation {
527534
/** Holds if some row in a CSV-based flow model appears to contain typos. */
528535
query predicate invalidModelRow(string msg) {
529536
exists(string pred, string namespace, string type, string name, string signature, string ext |
530-
sourceModel(namespace, type, _, name, signature, ext, _, _) and pred = "source"
537+
sourceModel(namespace, type, _, name, signature, ext, _, _, _) and pred = "source"
531538
or
532-
sinkModel(namespace, type, _, name, signature, ext, _, _) and pred = "sink"
539+
sinkModel(namespace, type, _, name, signature, ext, _, _, _) and pred = "sink"
533540
or
534-
summaryModel(namespace, type, _, name, signature, ext, _, _, _) and pred = "summary"
541+
summaryModel(namespace, type, _, name, signature, ext, _, _, _, _) and pred = "summary"
535542
|
536543
not namespace.regexpMatch("[a-zA-Z0-9_\\.]+") and
537544
msg = "Dubious namespace \"" + namespace + "\" in " + pred + " model."
@@ -550,9 +557,9 @@ module CsvValidation {
550557
)
551558
or
552559
exists(string pred, string input, string part |
553-
sinkModel(_, _, _, _, _, _, input, _) and pred = "sink"
560+
sinkModel(_, _, _, _, _, _, input, _, _) and pred = "sink"
554561
or
555-
summaryModel(_, _, _, _, _, _, input, _, _) and pred = "summary"
562+
summaryModel(_, _, _, _, _, _, input, _, _, _) and pred = "summary"
556563
|
557564
(
558565
invalidSpecComponent(input, part) and
@@ -567,9 +574,9 @@ module CsvValidation {
567574
)
568575
or
569576
exists(string pred, string output, string part |
570-
sourceModel(_, _, _, _, _, _, output, _) and pred = "source"
577+
sourceModel(_, _, _, _, _, _, output, _, _) and pred = "source"
571578
or
572-
summaryModel(_, _, _, _, _, _, _, output, _) and pred = "summary"
579+
summaryModel(_, _, _, _, _, _, _, output, _, _) and pred = "summary"
573580
|
574581
invalidSpecComponent(output, part) and
575582
not part = "" and
@@ -598,16 +605,22 @@ module CsvValidation {
598605
msg = "Invalid boolean \"" + b + "\" in " + pred + " model."
599606
)
600607
)
608+
or
609+
exists(string row, string kind | summaryModel(row) |
610+
kind = row.splitAt(";", 8) and
611+
not kind = ["taint", "value", "generated:taint", "generated:value"] and
612+
msg = "Invalid kind \"" + kind + "\" in summary model."
613+
)
601614
}
602615
}
603616

604617
pragma[nomagic]
605618
private predicate elementSpec(
606619
string namespace, string type, boolean subtypes, string name, string signature, string ext
607620
) {
608-
sourceModel(namespace, type, subtypes, name, signature, ext, _, _) or
609-
sinkModel(namespace, type, subtypes, name, signature, ext, _, _) or
610-
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _)
621+
sourceModel(namespace, type, subtypes, name, signature, ext, _, _, _) or
622+
sinkModel(namespace, type, subtypes, name, signature, ext, _, _, _) or
623+
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _)
611624
}
612625

613626
private string paramsStringPart(Callable c, int i) {

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ predicate summaryElement(
6262
exists(
6363
string namespace, string type, boolean subtypes, string name, string signature, string ext
6464
|
65-
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind) and
66-
c.asCallable() = interpretElement(namespace, type, subtypes, name, signature, ext) and
67-
generated = false
65+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, generated) and
66+
c.asCallable() = interpretElement(namespace, type, subtypes, name, signature, ext)
6867
)
6968
}
7069

@@ -123,9 +122,8 @@ predicate sourceElement(SourceOrSinkElement e, string output, string kind, boole
123122
exists(
124123
string namespace, string type, boolean subtypes, string name, string signature, string ext
125124
|
126-
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind) and
127-
e = interpretElement(namespace, type, subtypes, name, signature, ext) and
128-
generated = false
125+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, generated) and
126+
e = interpretElement(namespace, type, subtypes, name, signature, ext)
129127
)
130128
}
131129

@@ -138,9 +136,8 @@ predicate sinkElement(SourceOrSinkElement e, string input, string kind, boolean
138136
exists(
139137
string namespace, string type, boolean subtypes, string name, string signature, string ext
140138
|
141-
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind) and
142-
e = interpretElement(namespace, type, subtypes, name, signature, ext) and
143-
generated = false
139+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, generated) and
140+
e = interpretElement(namespace, type, subtypes, name, signature, ext)
144141
)
145142
}
146143

java/ql/src/utils/flowtestcasegenerator/FlowTestCase.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private class CallableToTest extends Callable {
4141
exists(
4242
string namespace, string type, boolean subtypes, string name, string signature, string ext
4343
|
44-
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _) and
44+
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _) and
4545
this = interpretElement(namespace, type, subtypes, name, signature, ext) and
4646
this.isPublic() and
4747
getRootType(this.getDeclaringType()).(RefType).isPublic()
@@ -64,7 +64,8 @@ private newtype TTestCase =
6464
string inputSpec, string outputSpec
6565
|
6666
any(TargetSummaryModelCsv tsmc).row(row) and
67-
summaryModel(namespace, type, subtypes, name, signature, ext, inputSpec, outputSpec, kind, row) and
67+
summaryModel(namespace, type, subtypes, name, signature, ext, inputSpec, outputSpec, kind,
68+
false, row) and
6869
callable = interpretElement(namespace, type, subtypes, name, signature, ext) and
6970
Private::External::interpretSpec(inputSpec, input) and
7071
Private::External::interpretSpec(outputSpec, output)

java/ql/src/utils/flowtestcasegenerator/GenerateFlowTestCase.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ query string getAParseFailure(string reason) {
2121
any(TargetSummaryModelCsv target).row(result) and
2222
any(SummaryModelCsv model).row(result) and
2323
(
24-
not summaryModel(_, _, _, _, _, _, _, _, _, result) and
24+
not summaryModel(_, _, _, _, _, _, _, _, _, _, result) and
2525
reason = "row could not be parsed"
2626
or
2727
exists(
2828
string namespace, string type, boolean subtypes, string name, string signature, string ext
2929
|
30-
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, result) and
30+
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _, result) and
3131
not interpretElement(namespace, type, subtypes, name, signature, ext) instanceof Callable and
3232
reason = "callable could not be resolved"
3333
)
3434
or
3535
exists(string inputSpec |
36-
summaryModel(_, _, _, _, _, _, inputSpec, _, _, result) and
36+
summaryModel(_, _, _, _, _, _, inputSpec, _, _, _, result) and
3737
not Private::External::interpretSpec(inputSpec, _) and
3838
reason = "input spec could not be parsed"
3939
)
4040
or
4141
exists(string outputSpec |
42-
summaryModel(_, _, _, _, _, _, _, outputSpec, _, result) and
42+
summaryModel(_, _, _, _, _, _, _, outputSpec, _, _, result) and
4343
not Private::External::interpretSpec(outputSpec, _) and
4444
reason = "output spec could not be parsed"
4545
)

0 commit comments

Comments
 (0)