forked from OSchip/llvm-project
[asan] Fix handling of %m in printf interceptor.
llvm-svn: 290632
This commit is contained in:
parent
deeca6de08
commit
f787cf7ee6
|
@ -435,10 +435,6 @@ static const char *printf_parse_next(const char *p, PrintfDirective *dir) {
|
|||
}
|
||||
|
||||
static int printf_get_value_size(PrintfDirective *dir) {
|
||||
if (dir->convSpecifier == 'm') {
|
||||
return sizeof(char *);
|
||||
}
|
||||
|
||||
if (char_is_one_of(dir->convSpecifier, "cCsS")) {
|
||||
unsigned charSize =
|
||||
format_get_char_size(dir->convSpecifier, dir->lengthModifier);
|
||||
|
@ -519,6 +515,9 @@ static void printf_common(void *ctx, const char *format, va_list aq) {
|
|||
// Dynamic precision
|
||||
SKIP_SCALAR_ARG(&aq, 'd', sizeof(int));
|
||||
}
|
||||
// %m does not require an argument: strlen(errno).
|
||||
if (dir.convSpecifier == 'm')
|
||||
continue;
|
||||
int size = printf_get_value_size(&dir);
|
||||
if (size == FSS_INVALID) {
|
||||
Report("WARNING: unexpected format specifier in printf "
|
||||
|
|
|
@ -256,4 +256,8 @@ TEST(SanitizerCommonInterceptors, Printf) {
|
|||
|
||||
// Checks for wide-character strings are not implemented yet.
|
||||
testPrintf("%ls", 1, 0);
|
||||
|
||||
testPrintf("%m", 0);
|
||||
testPrintf("%m%s", 1, test_buf_size);
|
||||
testPrintf("%s%m%s", 2, test_buf_size, test_buf_size);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// RUN: %clang_asan -O2 %s -o %t && %run %t
|
||||
|
||||
// FIXME: printf is not intercepted on Windows yet.
|
||||
// XFAIL: win32
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char s[5] = {'w', 'o', 'r', 'l', 'd'};
|
||||
// Test that %m does not consume an argument. If it does, %s would apply to
|
||||
// the 5-character buffer, resulting in a stack-buffer-overflow report.
|
||||
printf("%m %s, %.5s\n", "hello", s);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue