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

Add more safety checks to variadic function calls in checked scope #1182

Merged
merged 7 commits into from
Sep 10, 2021

Conversation

mgrang
Copy link

@mgrang mgrang commented Sep 9, 2021

The checking of variadic functions in checked scope follows these rules:

  1. All warnings issued by the -Wformat family of flags are errors in checked
    scope.
  2. No bounds checking of arguments to variadic functions like printf/scanf,
    etc is done.

For printf-like functions:
3. %s is allowed only with arg type _Nt_array_ptr or _Nt_checked.
4. %p is allowed with any arg type.
5. %n is disallowed.
6. For all other format specifiers, only scalar arg types are allowed.

For scanf-like functions:
7. %s is disallowed.
8. All width modifiers to format specifiers are disallowed.
9. %p is disallowed
10. %n is disallowed
11. For all other format specifiers, only _Ptr arg types are allowed.

The checking of variadic functions in checked scope follows these rules:
1. All warnings issued by the -Wformat family of flags are errors in checked
scope.
2. No bounds checking of arguments to variadic functions like printf/scanf,
etc is done.

For printf-like functions:
3. %s is allowed only with arg type _Nt_array_ptr or _Nt_checked.
4. %p is allowed with any arg type.
5. %n is disallowed.
6. For all other format specifiers, only scalar arg types are allowed.

For scanf-like functions:
7. %s is disallowed.
8. All width modifiers to format specifiers are disallowed.
9. %p is disallowed
10. %n is disallowed
11. For all other format specifiers, only _Ptr arg types are allowed.
@mgrang mgrang self-assigned this Sep 9, 2021
@mgrang mgrang changed the title Add more safety checks to variadic functions calls in checked scope Add more safety checks to variadic function calls in checked scope Sep 9, 2021
@mgrang mgrang changed the title Add more safety checks to variadic function calls in checked scope Add more safety checks to variadic functions call in checked scope Sep 9, 2021
@mgrang mgrang changed the title Add more safety checks to variadic functions call in checked scope Add more safety checks to variadic function calls in checked scope Sep 9, 2021
@mattmccutchen-cci
Copy link
Member

It looks like this PR closes off all the safety holes in #1178 except printf_s_count (passing an out-of-bounds _Nt_array_ptr to printf %s). It seems that one inherently requires a bounds check.

Copy link
Contributor

@sulekhark sulekhark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Mandeep Singh Grang and others added 3 commits September 9, 2021 11:27
Co-authored-by: Matt McCutchen (Correct Computation) <[email protected]>
Copy link
Contributor

@kkjeer kkjeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

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.

4 participants