diff --git a/cpp/ql/lib/change-notes/2026-11-26-uninitialized-arrays.md b/cpp/ql/lib/change-notes/2026-11-26-uninitialized-arrays.md new file mode 100644 index 000000000000..15b0845cf59b --- /dev/null +++ b/cpp/ql/lib/change-notes/2026-11-26-uninitialized-arrays.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* The `UninitializedNode` class from `semmle.code.cpp.dataflow.new.DataFlow` no longer includes stack-allocated arrays. \ No newline at end of file diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll index 9dbf7f8e73c5..156666a64bbf 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll @@ -809,7 +809,7 @@ module Public { * flow graph. */ class UninitializedNode extends AbstractUninitializedNode { - UninitializedNode() { indirectionIndex = 0 } + UninitializedNode() { indirectionIndex = 0 and not v.getUnspecifiedType() instanceof ArrayType } } /** diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp b/cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp index e0ad64674bc2..39c3ee4e5992 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp @@ -49,7 +49,7 @@ void following_pointers( // $ ast-def=sourceStruct1_ptr ir-def=*cleanArray1 ir-d int stackArray[2] = { source(), source() }; stackArray[0] = source(); - sink(stackArray); // $ ast,ir + sink(stackArray); // $ ast indirect_sink(stackArray); // $ ast ir=50:25 ir=50:35 ir=51:19 } diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected b/cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected index 2ead5d7b23a2..834f457def4e 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected @@ -172,6 +172,8 @@ astFlow | test.cpp:1312:7:1312:12 | call to source | test.cpp:1314:8:1314:8 | x | | test.cpp:1329:11:1329:16 | call to source | test.cpp:1330:10:1330:10 | i | | test.cpp:1335:10:1335:15 | buffer | test.cpp:1336:10:1336:18 | access to array | +| test.cpp:1342:8:1342:10 | buf | test.cpp:1344:8:1344:8 | p | +| test.cpp:1348:7:1348:7 | x | test.cpp:1350:8:1350:8 | p | | true_upon_entry.cpp:17:11:17:16 | call to source | true_upon_entry.cpp:21:8:21:8 | x | | true_upon_entry.cpp:27:9:27:14 | call to source | true_upon_entry.cpp:29:8:29:8 | x | | true_upon_entry.cpp:33:11:33:16 | call to source | true_upon_entry.cpp:39:8:39:8 | x | @@ -201,7 +203,6 @@ irFlow | clang.cpp:35:32:35:37 | call to source | clang.cpp:38:10:38:11 | m2 | | clang.cpp:40:42:40:47 | call to source | clang.cpp:42:18:42:19 | m2 | | clang.cpp:44:35:44:40 | call to source | clang.cpp:46:17:46:18 | m2 | -| clang.cpp:50:7:50:16 | definition of stackArray | clang.cpp:52:8:52:17 | stackArray | | clang.cpp:50:25:50:30 | call to source | clang.cpp:53:17:53:26 | *stackArray | | clang.cpp:50:35:50:40 | call to source | clang.cpp:53:17:53:26 | *stackArray | | clang.cpp:51:19:51:24 | call to source | clang.cpp:53:17:53:26 | *stackArray | @@ -291,11 +292,9 @@ irFlow | test.cpp:417:16:417:20 | intRefSource output argument | test.cpp:418:8:418:12 | local | | test.cpp:422:7:422:11 | definition of local | test.cpp:424:8:424:12 | local | | test.cpp:423:20:423:25 | intPointerSource output argument | test.cpp:424:8:424:12 | local | -| test.cpp:433:7:433:11 | definition of local | test.cpp:435:8:435:12 | local | | test.cpp:434:20:434:24 | intPointerSource output argument | test.cpp:436:8:436:13 | * ... | | test.cpp:440:7:440:11 | definition of local | test.cpp:442:8:442:12 | local | | test.cpp:441:18:441:23 | intArraySource output argument | test.cpp:442:8:442:12 | local | -| test.cpp:448:7:448:11 | definition of local | test.cpp:450:8:450:12 | local | | test.cpp:449:18:449:22 | intArraySource output argument | test.cpp:451:8:451:13 | * ... | | test.cpp:456:26:456:32 | source1 | test.cpp:457:9:457:22 | (statement expression) | | test.cpp:456:26:456:32 | source1 | test.cpp:468:8:468:12 | local | diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp b/cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp index 6e80fa75aa02..aec942f86ac6 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp @@ -432,7 +432,7 @@ void intPointerSourceCaller() { void intPointerSourceCaller2() { int local[1]; intPointerSource(local); - sink(local); // $ ast=434:20 ir SPURIOUS: ast=433:7 + sink(local); // $ ast=434:20 SPURIOUS: ast=433:7 sink(*local); // $ ast=434:20 ir SPURIOUS: ast=433:7 } @@ -447,7 +447,7 @@ void intArraySourceCaller() { void intArraySourceCaller2() { int local[2]; intArraySource(local, 2); - sink(local); // $ ast=449:18 ir SPURIOUS: ast=448:7 + sink(local); // $ ast=449:18 SPURIOUS: ast=448:7 sink(*local); // $ ast=449:18 ir SPURIOUS: ast=448:7 } @@ -1336,4 +1336,16 @@ void certain_def_uninitialized_instruction_test() { sink(buffer[0]); // $ SPURIOUS: ast buffer[0] = source(); } +} + +void uninitialized_array_address() { + char buf[10]; + char *p = buf; + sink(p); // $ SPURIOUS: ast +} + +void uninitialized_scalar_address() { + int x; + int *p = &x; + sink(p); // $ SPURIOUS: ast } \ No newline at end of file diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/uninitialized.expected b/cpp/ql/test/library-tests/dataflow/dataflow-tests/uninitialized.expected index 0850b577dcb7..d828e80a9783 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/uninitialized.expected +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/uninitialized.expected @@ -61,3 +61,5 @@ | test.cpp:1137:7:1137:10 | data | test.cpp:1140:10:1140:13 | data | | test.cpp:1335:10:1335:15 | buffer | test.cpp:1336:10:1336:15 | buffer | | test.cpp:1335:10:1335:15 | buffer | test.cpp:1337:5:1337:10 | buffer | +| test.cpp:1342:8:1342:10 | buf | test.cpp:1343:13:1343:15 | buf | +| test.cpp:1348:7:1348:7 | x | test.cpp:1349:13:1349:13 | x |