Skip to content

Commit 9690ff6

Browse files
committed
C#: Address review comments.
1 parent 5510d05 commit 9690ff6

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,45 @@ module EntityFramework {
370370
)
371371
}
372372

373+
/**
374+
* Holds if `input` is a valid summary component stack for property `mapped` for this.
375+
*/
376+
pragma[noinline]
377+
predicate input(SummaryComponentStack input, Property mapped) {
378+
exists(PropertyContent head, SummaryComponentStack tail |
379+
this.requiresComponentStackIn(head, _, tail, _) and
380+
head.getProperty() = mapped and
381+
mapped = this.getAColumnProperty(_) and
382+
input = SummaryComponentStack::push(SummaryComponent::content(head), tail)
383+
)
384+
}
385+
386+
/**
387+
* Holds if `output` is a valid summary component stack for the getter of `dbSet`
388+
* for property `mapped` for this.
389+
*/
390+
pragma[noinline]
391+
predicate output(SummaryComponentStack output, Property mapped, DbContextClassSetProperty dbSet) {
392+
exists(PropertyContent head, SummaryComponentStack tail |
393+
this.requiresComponentStackOut(head, _, tail, _, dbSet) and
394+
head.getProperty() = mapped and
395+
mapped = this.getAColumnProperty(_) and
396+
output = SummaryComponentStack::push(SummaryComponent::content(head), tail)
397+
)
398+
}
399+
400+
/**
401+
* Gets the synthetic name for the getter of `dbSet` for property `mapped` for this,
402+
* where `output` is a valid summary component stack for the getter of `dbSet`
403+
* for the property `mapped`.
404+
*/
373405
pragma[nomagic]
374-
string getSyntheticNames(
375-
SummaryComponentStack input, SummaryComponentStack output, DbContextClassSetProperty dbSet
406+
string getSyntheticName(
407+
SummaryComponentStack output, Property mapped, DbContextClassSetProperty dbSet
376408
) {
377-
exists(Property mapped |
378-
this = dbSet.getDbContextClass() and
379-
input(this, input, mapped) and
380-
output(this, output, mapped, dbSet) and
381-
result = dbSet.getSyntheticName() + "#" + SummaryComponentStack::getComponentStack(output)
382-
)
409+
this = dbSet.getDbContextClass() and
410+
this.output(output, mapped, dbSet) and
411+
result = dbSet.getFullName() + "#" + SummaryComponentStack::getComponentStack(output)
383412
}
384413
}
385414

@@ -389,9 +418,9 @@ module EntityFramework {
389418
DbContextClassSetProperty() { this = c.getADbSetProperty(_) }
390419

391420
/**
392-
* Gets the string representation for a synthetic identifier for this.
421+
* Gets the fully qualified name for this.
393422
*/
394-
string getSyntheticName() {
423+
string getFullName() {
395424
exists(string qualifier, string type, string name |
396425
this.hasQualifiedName(qualifier, type, name)
397426
|
@@ -400,41 +429,11 @@ module EntityFramework {
400429
}
401430

402431
/**
403-
* Gets the context class where this is a Db set property.
432+
* Gets the context class where this is a DbSet property.
404433
*/
405434
DbContextClass getDbContextClass() { result = c }
406435
}
407436

408-
/**
409-
* Holds if `input` is a valid summary component stack for property `mapped`
410-
* for the context class `c`.
411-
*/
412-
pragma[noinline]
413-
predicate input(DbContextClass c, SummaryComponentStack input, Property mapped) {
414-
exists(PropertyContent head, SummaryComponentStack tail |
415-
c.requiresComponentStackIn(head, _, tail, _) and
416-
head.getProperty() = mapped and
417-
mapped = c.getAColumnProperty(_) and
418-
input = SummaryComponentStack::push(SummaryComponent::content(head), tail)
419-
)
420-
}
421-
422-
/**
423-
* Holds if `output` is a valid summary component stack for the getter of `dbSet`
424-
* for property `mapped` for the context class `c`.
425-
*/
426-
pragma[noinline]
427-
predicate output(
428-
DbContextClass c, SummaryComponentStack output, Property mapped, DbContextClassSetProperty dbSet
429-
) {
430-
exists(PropertyContent head, SummaryComponentStack tail |
431-
c.requiresComponentStackOut(head, _, tail, _, dbSet) and
432-
head.getProperty() = mapped and
433-
mapped = c.getAColumnProperty(_) and
434-
output = SummaryComponentStack::push(SummaryComponent::content(head), tail)
435-
)
436-
}
437-
438437
private class DbContextClassSetPropertySynthetic extends EFSummarizedCallable {
439438
private DbContextClassSetProperty p;
440439

@@ -445,7 +444,7 @@ module EntityFramework {
445444
) {
446445
exists(string name, DbContextClass c |
447446
preservesValue = true and
448-
name = c.getSyntheticNames(_, output, p) and
447+
name = c.getSyntheticName(output, _, p) and
449448
input = SummaryComponentStack::syntheticGlobal(name)
450449
)
451450
}
@@ -459,21 +458,20 @@ module EntityFramework {
459458
override predicate propagatesFlow(
460459
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
461460
) {
462-
exists(string name |
461+
exists(string name, Property mapped |
463462
preservesValue = true and
464-
name = c.getSyntheticNames(input, _, _) and
463+
c.input(input, mapped) and
464+
name = c.getSyntheticName(_, mapped, _) and
465465
output = SummaryComponentStack::syntheticGlobal(name)
466466
)
467467
}
468468
}
469469

470470
/**
471-
* Add all `DbContext` property names as potential synthetic globals.
471+
* Add all possible synthetic global names.
472472
*/
473473
private class EFSummarizedCallableSyntheticGlobal extends SummaryComponent::SyntheticGlobal {
474-
EFSummarizedCallableSyntheticGlobal() {
475-
this = any(DbContextClass c).getSyntheticNames(_, _, _)
476-
}
474+
EFSummarizedCallableSyntheticGlobal() { this = any(DbContextClass c).getSyntheticName(_, _, _) }
477475
}
478476

479477
private class DbContextSaveChangesRequiredSummaryComponentStack extends RequiredSummaryComponentStack

0 commit comments

Comments
 (0)