Skip to content

Commit aa9ab41

Browse files
authored
Merge pull request github#5059 from geoffw0/mswprintf
C++: Exclude custom vprintf implementations from primitiveVariadicFormatter.
2 parents 5db1984 + 708d387 commit aa9ab41

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

cpp/ql/src/semmle/code/cpp/commons/Printf.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ predicate primitiveVariadicFormatter(
5050
then formatParamIndex = f.getNumberOfParameters() - 3
5151
else formatParamIndex = f.getNumberOfParameters() - 2
5252
) and
53-
if type = "" then outputParamIndex = -1 else outputParamIndex = 0 // Conveniently, these buffer parameters are all at index 0.
53+
(
54+
if type = "" then outputParamIndex = -1 else outputParamIndex = 0 // Conveniently, these buffer parameters are all at index 0.
55+
) and
56+
not exists(f.getBlock()) // exclude functions with an implementation in the snapshot as they may not be standard implementations.
5457
}
5558

5659
private predicate callsVariadicFormatter(
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| printf.cpp:33:31:33:37 | test | This argument should be of type 'char *' but is of type 'char16_t *' |
2-
| printf.cpp:45:29:45:35 | test | This argument should be of type 'char *' but is of type 'char16_t *' |
3-
| printf.cpp:52:29:52:35 | test | This argument should be of type 'char16_t *' but is of type 'wchar_t *' |
1+
| printf.cpp:31:31:31:37 | test | This argument should be of type 'char *' but is of type 'char16_t *' |
2+
| printf.cpp:43:29:43:35 | test | This argument should be of type 'char *' but is of type 'char16_t *' |
3+
| printf.cpp:50:29:50:35 | test | This argument should be of type 'char16_t *' but is of type 'wchar_t *' |
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| printf.cpp:15:5:15:12 | swprintf | char | char16_t | char16_t |
2-
| printf.cpp:26:5:26:11 | sprintf | char | char16_t | char16_t |
1+
| printf.cpp:13:5:13:12 | swprintf | char | char16_t | char16_t |
2+
| printf.cpp:24:5:24:11 | sprintf | char | char16_t | char16_t |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_two_byte_wprintf/printf.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ typedef void *va_list;
88
#define va_start(va, other)
99
#define va_end(args)
1010

11-
int vswprintf(WCHAR *dest, WCHAR *format, va_list args) {
12-
return 0;
13-
}
11+
int vswprintf(WCHAR *dest, WCHAR *format, va_list args);
1412

1513
int swprintf(WCHAR *dest, WCHAR *format, ...) {
1614
va_list args;

0 commit comments

Comments
 (0)