-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[-Wunsafe-buffer-usage] Accept calls to some libc functions with annotated arguments #10088
base: next
Are you sure you want to change the base?
[-Wunsafe-buffer-usage] Accept calls to some libc functions with annotated arguments #10088
Conversation
…tated arguments - `printf`, `fprintf` `snprintf` functions accept `__null_terminated` - `snprintf` function accepts `__counted_by/__sized_by` - functions consuming a single string pointer like `strlen` or `atoi` accept `__null_terminated` Generalized `isCountAttributedPointerArgumentSafe` so that it is shared by interoperation gadgets and the unsafe libc gadget. (A follow-up change to rdar://138798346)
CC @dtarditi |
This PR depends on #10060 |
@@ -747,7 +747,7 @@ const Expr *extractExtentFromSubviewDataCall(ASTContext &Context, | |||
static bool hasIntegeralConstant(const Expr *E, uint64_t Val, ASTContext &Ctx) { | |||
Expr::EvalResult ER; | |||
|
|||
if (E->EvaluateAsConstantExpr(ER, Ctx)) { | |||
if (E->EvaluateAsInt(ER, Ctx)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://github.com/llvm/llvm-project/pull/124022/files, the result of EvaluateAsConstantExpr
may not necessarily be able to getInt()
later.
@@ -23,7 +23,7 @@ namespace std { | |||
T* p; | |||
T *c_str(); | |||
T *data(); | |||
unsigned size_bytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A mistake I made in the test---std::string has no size_bytes
method.
@@ -366,6 +366,7 @@ isInUnspecifiedUntypedContext(internal::Matcher<Stmt> InnerMatcher) { | |||
|
|||
namespace { | |||
|
|||
/* TO_UPSTREAM(BoundsSafetyInterop) ON */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume there is no problem in upstreaming the part of the interop in UnsafeBufferUsage.cpp? @patrykstefanski
printf
,fprintf
snprintf
functions accept__null_terminated
snprintf
function accepts__counted_by/__sized_by
strlen
oratoi
accept__null_terminated
Generalized
isCountAttributedPointerArgumentSafe
so that it is shared by interoperation gadgets and the unsafe libc gadget.(A follow-up change to rdar://138798346)