-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-112301: Add -Wformat=2 compiler option to NODIST #122474
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
base: main
Are you sure you want to change the base?
Conversation
Python/getversion.c
Outdated
@@ -19,8 +19,17 @@ void _Py_InitVersion(void) | |||
#else | |||
const char *buildinfo_format = "%.80s (%.80s) %.80s"; | |||
#endif | |||
// The format string is defined above and is observably safe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be switched to a #define
d literal? That way it could look safe to the compiler, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a change. I figure instead of going through the trouble defining a format string in the preprocessor #if/#else blocks and adding all of the diagnostic pragmas we can just put the PyOS_snprintf()
with the relevant format string literals in the respective #if/#else blocks. We eliminate the root cause of the warning instead of ignore it.
Objects/unicodeobject.c
Outdated
// is only assigned known constant values. Ignore warnings related | ||
// to the format string not being a string literal. | ||
#if defined(__GNUC__) || defined(__clang__) | ||
#pragma GCC diagnostic push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using _Py_COMP_DIAG_PUSH
/_Py_COMP_DIAG_POP
, and adding a macro like _Py_COMP_DIAG_IGNORE_DEPR_DECLS
, to make this easier to port to other compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@encukou created macro for ignoring format nonliterals and applied it to this block
I wanted to see if it's possible to avoid the warning altogether -- and had an implementation before I realized I should have probably delegated it. |
That PR is merged now :) |
Misc/NEWS.d/next/Security/2024-07-30-17-34-47.gh-issue-112301.8J8WhZ.rst
Outdated
Show resolved
Hide resolved
Objects/mimalloc/ * | ||
Python/pylifecycle.c 1 | ||
Python/sysmodule.c 1 | ||
Python/tracemalloc.c 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you please add the missing newline at EOF?
Is this still relevant? I stumbled upon that and wondered whether it's something relevant to add in this PR or in a separate PR (I was working with |
This adds
-Wformat
and-Wformat=2
to theCFLAGS_NODIST
set of compiler flags. This is a warning flag that relates for format strings and for more information you can take a look at the OpenSSF guidance on this flag.This does generate a few warnings in
build_ubuntu
and the new warning checker catches them catches them:unicodeobject.c
warnings look like they could be ignored since format strings forsprintf
operations are pulled from a const array of const format strings, and the variable that indexes these arrays is set from constants. However if we add this file to.warningignore_ubuntu
then if either of those things change maybe vulnerabilities could be introduced.As for
getversion.c
it also could be ignored. I don't think there is too much of a concern in putting this in the warning ignore file.This change should require pre-merge build bots @corona10
Attn: @hugovk
EDIT: Removed content from the issue that pertained to already merged tooling options