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

Annotate printf and scanf type functions #85

Closed
hauke opened this issue Nov 12, 2019 · 2 comments
Closed

Annotate printf and scanf type functions #85

hauke opened this issue Nov 12, 2019 · 2 comments
Assignees
Milestone

Comments

@hauke
Copy link

hauke commented Nov 12, 2019

GCC and clang are able to detect if the format string modifiers are matching the given variables. As long as the standard c format modifiers are used, see #68 the printf and scanf type functions should be annotated with these attributes:

__attribute__ ((format (printf, 2, 3)));

The first argument is the position of the format string and the second of the var args parameter.

This is supported for printf, scanf, strftime or strfmon type functions by GCC and CLANG.

How should this be best implemented?
When I used scanf_s() with a wrong format modifier my code will compile without any warning, but I would like to get a warning about this to see the problems at compile time and not introduce potential security problems.

@rurban rurban added this to the 3.6 milestone Aug 27, 2020
@rurban rurban self-assigned this Aug 27, 2020
@rurban
Copy link
Owner

rurban commented Aug 27, 2020

I'll rather probe for it and add it to the generated safe_types.h
icc can do it also, who knows what other crazy cross compilers also.
The wprintf and wscanf format attributes are waiting to be implemented, patches do exist since 2008.

rurban added a commit that referenced this issue Aug 27, 2020
See GH #85. Annotate our decls accordingly.
rurban added a commit that referenced this issue Aug 27, 2020
@rurban rurban closed this as completed Aug 29, 2020
@hauke
Copy link
Author

hauke commented Sep 2, 2020

Thanks for adding this.

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

No branches or pull requests

2 participants