Skip to content
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

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

ziqingluo-90
Copy link

  • 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)

…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)
@ziqingluo-90
Copy link
Author

CC @dtarditi

@ziqingluo-90
Copy link
Author

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)) {
Copy link
Author

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();
Copy link
Author

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 */
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant