Skip to content

Commit a061811

Browse files
committed
Merge branch 'master' into rdmarsh/cpp/ir-flow-through-outparams
Pick up new test for user-defined swap functions
2 parents b579e6a + bbb69d5 commit a061811

File tree

34 files changed

+187
-55
lines changed

34 files changed

+187
-55
lines changed

change-notes/1.24/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
2020
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2121
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed false positive results in template code. |
2222
| Missing return statement (`cpp/missing-return`) | Fewer false positive results | Functions containing `asm` statements are no longer highlighted by this query. |
23+
| Missing return statement (`cpp/missing-return`) | More accurate locations | Locations reported by this query are now more accurate in some cases. |
2324
| No space for zero terminator (`cpp/no-space-for-terminator`) | More correct results | String arguments to formatting functions are now (usually) expected to be null terminated strings. |
2425
| Hard-coded Japanese era start date (`cpp/japanese-era/exact-era-date`) | | This query is no longer run on LGTM. |
2526
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | This query has been modified to be more conservative when identifying which pointers point to null-terminated strings. This approach produces fewer, more accurate results. |

cpp/ql/src/jsf/4.13 Functions/AV Rule 114.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
3030
) and
3131
exists(ReturnStmt s |
3232
f.getAPredecessor() = s and
33-
blame = s.getAPredecessor()
33+
(
34+
blame = s.getAPredecessor() and
35+
count(blame.getASuccessor()) = 1
36+
or
37+
blame = s and
38+
exists(ControlFlowNode pred | pred = s.getAPredecessor() | count(pred.getASuccessor()) != 1)
39+
)
3440
)
3541
}
3642

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,8 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
20892089

20902090
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
20912091

2092+
int getParameterPos() { p.isParameterOf(_, result) }
2093+
20922094
override string toString() { result = p + ": " + ap }
20932095

20942096
predicate hasLocationInfo(
@@ -2482,13 +2484,15 @@ pragma[nomagic]
24822484
private predicate paramFlowsThrough(
24832485
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, Configuration config
24842486
) {
2485-
exists(PathNodeMid mid, ReturnNodeExt ret |
2487+
exists(PathNodeMid mid, ReturnNodeExt ret, int pos |
24862488
mid.getNode() = ret and
24872489
kind = ret.getKind() and
24882490
cc = mid.getCallContext() and
24892491
sc = mid.getSummaryCtx() and
24902492
config = mid.getConfiguration() and
2491-
ap = mid.getAp()
2493+
ap = mid.getAp() and
2494+
pos = sc.getParameterPos() and
2495+
not kind.(ParamUpdateReturnKind).getPosition() = pos
24922496
)
24932497
}
24942498

0 commit comments

Comments
 (0)