Skip to content

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

Merged
mgrang merged 7 commits into
masterfrom
varargs3
Sep 10, 2021
Merged

Add more safety checks to variadic function calls in checked scope#1182
mgrang merged 7 commits into
masterfrom
varargs3

Conversation

@mgrang

@mgrang mgrang commented Sep 9, 2021

Copy link
Copy Markdown

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 requested review from kkjeer and sulekhark September 9, 2021 02:16
@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
Copy Markdown
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.

@sulekhark sulekhark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you!

Comment thread clang/lib/Sema/SemaChecking.cpp Outdated
Mandeep Singh Grang and others added 3 commits September 9, 2021 11:27
Co-authored-by: Matt McCutchen (Correct Computation) <matt@correctcomputation.com>

@kkjeer kkjeer left a comment

Copy link
Copy Markdown
Contributor

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