You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#1174 added support to call variadic functions in checked scope. There are several checks which are yet to be implemented. The PR does not do any bounds checking for the arguments to printf/scanf like functions. The following issues were raised by @mattmccutchen-cci on the PR.
I realize I may have waited a little too late to post this, but I tested this PR and found several holes in the new checking. If you save the code below as printf-checking-bugs.c and then run clang -o printf-checking-bugs printf-checking-bugs.c and ./printf-checking-bugs percent_n, etc., you can see the SEGV. If you don't want to address the problems in this PR, I can copy the examples to a new issue.
#pragma CHECKED_SCOPE on
#include<string.h>#include<stdio.h>#include<unistd.h>#include<fcntl.h>#defineTEST(_name) else if (strcmp(test_name, #_name) == 0)
intmain(intargc, _Nt_array_ptr<_Nt_array_ptr<char>> argv : count(argc)) {
_Nt_array_ptr<char>test_name=argv[1];
if (!test_name) {
fprintf(stderr, "No test name specified\n");
return1;
}
if (0) {}
TEST(percent_n) {
// Missing check that %n argument is a _Ptr.intarr_Checked[1];
printf("hello\n%n", arr+123456789);
}
TEST(scanf_scalar) {
// Missing check that _any_ scalar scanf argument is a _Ptr.intarr_Checked[1];
sscanf("42", "%d", arr+123456789);
}
TEST(printf_s_count) {
// Missing check that printf %s argument has at least count(0).charbuf_Nt_checked[1];
printf("%s", buf+123456789);
}
TEST(scanf_p) {
// scanf reads an arbitrary _Ptr<void> via %p. The right solution here may// be to disallow _Ptr<void>// (https://github.com/microsoft/checkedc/issues/335). I couldn't find any// other way to exploit %p, but that doesn't mean there isn't any._Ptr<void>q=0;
sscanf("0x1", "%p", &q);
_Ptr<char>p= (_Ptr<char>)q;
(*p)++;
}
TEST(scanf_s_overflow) {
// scanf %s overflows the output buffer. I guess the compiler should require// the format string to specify a maximum width and check it against the// bounds of the argument?charfield_Nt_checked[10];
charinput_Nt_checked[1000];
memset(input, 'x', sizeofinput-1);
sscanf(input, "%s", field);
}
else {
fprintf(stderr, "Unknown test name\n");
return1;
}
return0;
}
This issue was copied from checkedc/checkedc-clang#1178
#1174 added support to call variadic functions in checked scope. There are several checks which are yet to be implemented. The PR does not do any bounds checking for the arguments to printf/scanf like functions. The following issues were raised by @mattmccutchen-cci on the PR.
I realize I may have waited a little too late to post this, but I tested this PR and found several holes in the new checking. If you save the code below as
printf-checking-bugs.c
and then runclang -o printf-checking-bugs printf-checking-bugs.c
and./printf-checking-bugs percent_n
, etc., you can see the SEGV. If you don't want to address the problems in this PR, I can copy the examples to a new issue.Originally posted by @mattmccutchen-cci in checkedc/checkedc-clang#1174 (comment)
The text was updated successfully, but these errors were encountered: