From b19c64896544547c98167b0705a1f2dee592e8ad Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 7 Apr 2026 10:43:15 +0200 Subject: [PATCH 1/2] C++: Add heuristic for GNU autoconf config files --- cpp/ql/lib/change-notes/2026-04-07-autoconf.md | 4 ++++ cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll | 7 +++++++ .../ExprHasNoEffect/autoconf/ExprHasNoEffect.expected | 2 ++ .../ExprHasNoEffect/autoconf/ExprHasNoEffect.qlref | 1 + .../Likely Typos/ExprHasNoEffect/autoconf/conftest.c | 6 ++++++ .../Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c | 6 ++++++ .../Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp | 6 ++++++ .../Likely Typos/ExprHasNoEffect/autoconf/conftest.h | 3 +++ .../Likely Typos/ExprHasNoEffect/autoconf/conftest123.c | 6 ++++++ .../Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c | 6 ++++++ 10 files changed, 47 insertions(+) create mode 100644 cpp/ql/lib/change-notes/2026-04-07-autoconf.md create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.expected create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.qlref create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.h create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c create mode 100644 cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c diff --git a/cpp/ql/lib/change-notes/2026-04-07-autoconf.md b/cpp/ql/lib/change-notes/2026-04-07-autoconf.md new file mode 100644 index 00000000000..9f04417b8e2 --- /dev/null +++ b/cpp/ql/lib/change-notes/2026-04-07-autoconf.md @@ -0,0 +1,4 @@ +--- +category: feature +--- +* Added a subclass `AutoconfConfigureTestFile` of `ConfigurationTestFile` that represents files created by GNU autoconf configure scripts to test the build configuration. diff --git a/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll b/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll index b39c1009f07..ae90caa0e63 100644 --- a/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll +++ b/cpp/ql/lib/semmle/code/cpp/ConfigurationTestFile.qll @@ -42,3 +42,10 @@ class MesonPrivateTestFile extends ConfigurationTestFile { ) } } + +/** + * A file created by a GNU autoconf configure script to test the system configuration. + */ +class AutoconfConfigureTestFile extends ConfigurationTestFile { + AutoconfConfigureTestFile() { this.getBaseName().regexpMatch("conftest[0-9]*\\.c(pp)?") } +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.expected b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.expected new file mode 100644 index 00000000000..a87d2ddbd1b --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.expected @@ -0,0 +1,2 @@ +| conftest.c.c:4:3:4:8 | call to strlen | This expression has no effect (because $@ has no external side effects). | conftest.h:3:8:3:13 | strlen | strlen | +| conftest_abc.c:4:3:4:8 | call to strlen | This expression has no effect (because $@ has no external side effects). | conftest.h:3:8:3:13 | strlen | strlen | diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.qlref b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.qlref new file mode 100644 index 00000000000..82a90f5413a --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/ExprHasNoEffect.qlref @@ -0,0 +1 @@ +Likely Bugs/Likely Typos/ExprHasNoEffect.ql diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c new file mode 100644 index 00000000000..53c647d194b --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c @@ -0,0 +1,6 @@ +#include "conftest.h" + +int main2() { + strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + return 0; +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c new file mode 100644 index 00000000000..1c9667d7463 --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c @@ -0,0 +1,6 @@ +#include "conftest.h" + +int main3() { + strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + return 0; +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp new file mode 100644 index 00000000000..9cd23976e14 --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp @@ -0,0 +1,6 @@ +#include "conftest.h" + +int main4() { + strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + return 0; +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.h b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.h new file mode 100644 index 00000000000..9cf6f7e0d9f --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.h @@ -0,0 +1,3 @@ +typedef long long size_t; + +size_t strlen(const char *s); diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c new file mode 100644 index 00000000000..e79a7361ffc --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c @@ -0,0 +1,6 @@ +#include "conftest.h" + +int main5() { + strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + return 0; +} diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c new file mode 100644 index 00000000000..d6db9c0b3e0 --- /dev/null +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c @@ -0,0 +1,6 @@ +#include "conftest.h" + +int main1() { + strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + return 0; +} From 04cfd37f53be166f4ab33c520f293958256c8372 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Tue, 7 Apr 2026 10:52:12 +0200 Subject: [PATCH 2/2] C++: Fix comments in tests --- .../Likely Typos/ExprHasNoEffect/autoconf/conftest.c | 2 +- .../Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c | 2 +- .../Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp | 2 +- .../Likely Typos/ExprHasNoEffect/autoconf/conftest123.c | 2 +- .../Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c index 53c647d194b..2e067f5c433 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c @@ -1,6 +1,6 @@ #include "conftest.h" int main2() { - strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + strlen(""); // GOOD: conftest files are ignored return 0; } diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c index 1c9667d7463..4ff7c225335 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.c.c @@ -1,6 +1,6 @@ #include "conftest.h" int main3() { - strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + strlen(""); // BAD: not a `conftest` file, as `conftest` is not directly followed by the extension or a sequence of numbers. return 0; } diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp index 9cd23976e14..7b8edf64261 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest.cpp @@ -1,6 +1,6 @@ #include "conftest.h" int main4() { - strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + strlen(""); // GOOD: conftest files are ignored return 0; } diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c index e79a7361ffc..b227d53ad2a 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest123.c @@ -1,6 +1,6 @@ #include "conftest.h" int main5() { - strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + strlen(""); // GOOD: conftest files are ignored return 0; } diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c index d6db9c0b3e0..88215d7434c 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/autoconf/conftest_abc.c @@ -1,6 +1,6 @@ #include "conftest.h" int main1() { - strlen(""); // GOOD: the source file occurs in a `CMakeFiles/CMakeScratch/TryCompile-...` directory + strlen(""); // BAD: not a `conftest` file, as `conftest` is not directly followed by the extension or a sequence of numbers. return 0; }