-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot compile with -Werror=format-security #1675
Comments
Found the same issue in |
Filed as internal issue #USD-7015 |
pixar-oss
pushed a commit
that referenced
this issue
Dec 18, 2021
This fixes warnings (or errors in strict builds) like: error: format not a string literal and no format arguments [-Werror=format-security] Also enable "-Wformat-security" by default Fixes #1675 (Internal change: 2207145)
lkerley
pushed a commit
to imageworks/USD
that referenced
this issue
Jan 7, 2022
Stop accidentally treating a message as a printf-style format string in three places. See details in issue PixarAnimationStudios#1675.
lkerley
pushed a commit
to imageworks/USD
that referenced
this issue
Jan 7, 2022
This fixes warnings (or errors in strict builds) like: error: format not a string literal and no format arguments [-Werror=format-security] Also enable "-Wformat-security" by default Fixes PixarAnimationStudios#1675 (Internal change: 2207145)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description of Issue
USD 21.11 cannot compile with
-Werror=format-security
.Steps to Reproduce
-Werror=format-security
.System Information (OS, Hardware)
Fedora Linux Rawhide (development version), x86_64.
Package Versions
21.11
Build Flags
-Werror=format-security
See the downstream issue for upgrading to 21.11, beginning with Comment 6.
The error is:
The lines around the error are:
For the definition of
class TfDebug
, seepxr/base/tf/debug.h
. We find thatTfDebug::Helper
is astruct
defined as follows:The problem is that
ss.str().c_str()
is achar const*
, so we are using the second overload of theTfDebug::Helper::Msg
static method, which treats the string as aprintf
-style format string. This is an opportunity for havoc (https://capec.mitre.org/data/definitions/135.html), which is why it is marked with theARCH_PRINTF_FUNCTION(1, 2)
macro—which expands to__attribute__((format(printf, 1, 2)))
, telling GCC it is aprintf
-style formatting function, and triggering a warning if the format string is not a compile-time constant—and why Fedora’s default compiler flags asks GCC to treat this warning as an error (-Werror=format-security
).The fix is simple: use the
std::string
copy of thestd::stringstream
contents directly in order to use the first overload, rather than calling itsc_str()
method.TfDebug::Helper().Msg(ss.str());
I will follow up with a PR to make this change.
The text was updated successfully, but these errors were encountered: