Skip to content

[🍒][-Wunsafe-buffer-usage] Accept calls to some libc functions with annotated arguments & Let libc warnings yield to bounds attributes #10182

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

Merged
merged 3 commits into from
Mar 7, 2025

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)

  • [Upstream][C++ Safe Buffers] Let libc warnings yield to bounds attributes

For a call to an unsafe libc function, do not warn about it if its
callee function has any bounds attributes. Because we can verify the
safety of the call using bounds attributes.

(rdar://140138380)

ziqingluo-90 and others added 2 commits March 5, 2025 16:31
…utes

For a call to an unsafe libc function, do not warn about it if its
callee function has any bounds attributes. Because we can verify the
safety of the call using bounds attributes.

(rdar://140138380)
…tated arguments (#10088)

* [-Wunsafe-buffer-usage] Accept calls to some libc functions with annotated 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 ziqingluo-90 requested a review from a team as a code owner March 6, 2025 01:07
@ziqingluo-90
Copy link
Author

Cherry-picking #10088, which depends on "[C++ Safe Buffers] Let libc warnings yield to bounds attributes" that was forgotten to be cherry-picked to stable/20240723.

@ziqingluo-90
Copy link
Author

@swift-ci test

@ziqingluo-90
Copy link
Author

@swift-ci test llvm

@ziqingluo-90
Copy link
Author

@swift-ci test

@ziqingluo-90
Copy link
Author

@swift-ci test llvm

@ziqingluo-90 ziqingluo-90 merged commit 5242921 into stable/20240723 Mar 7, 2025
5 checks passed
@ziqingluo-90 ziqingluo-90 deleted the dev/ziqing/cherrypick-10088 branch March 7, 2025 04:23
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