From a8377b5ce4ab0f7203925b71ca46b1873457eb6d Mon Sep 17 00:00:00 2001 From: Joey Dumont Date: Mon, 3 May 2021 21:19:14 -0400 Subject: [PATCH] Trying to fix Werror=format-security warnings. --- ...rity-warnings-in-libcpp-expr.c-macro.patch | 82 +++++++++++++++++++ PKGBUILD | 6 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch diff --git a/0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch b/0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch new file mode 100644 index 0000000..b14c9cc --- /dev/null +++ b/0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch @@ -0,0 +1,82 @@ +From 56747152bde5d1a129482d594875d957fc48a402 Mon Sep 17 00:00:00 2001 +From: Joey Dumont +Date: Mon, 3 May 2021 14:42:22 -0400 +Subject: [PATCH] Fix format-security warnings. + +Compiling gcc with -Wformat-security turns up some errors. To fix them, we need to specify the +format string rather than directly passing a variable to printf or, in this case, to functions that +eventually call printf. +--- + libcpp/expr.c | 6 +++--- + libcpp/macro.c | 8 ++++---- + 2 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/libcpp/expr.c b/libcpp/expr.c +index 2ae9be07c..573a5563b 100644 +--- a/libcpp/expr.c ++++ b/libcpp/expr.c +@@ -799,10 +799,10 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, + + if (CPP_OPTION (pfile, c99)) + cpp_warning_with_line (pfile, CPP_W_LONG_LONG, virtual_location, +- 0, message); ++ 0, "%s", message); + else + cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG, +- virtual_location, 0, message); ++ virtual_location, 0, "%s", message); + } + + result |= CPP_N_INTEGER; +@@ -815,7 +815,7 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, + if (radix == 2 + && !CPP_OPTION (pfile, binary_constants) + && CPP_PEDANTIC (pfile)) +- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, ++ cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, "%s", + CPP_OPTION (pfile, cplusplus) + ? N_("binary constants are a C++14 feature " + "or GCC extension") +diff --git a/libcpp/macro.c b/libcpp/macro.c +index 2573f316b..e00771e86 100644 +--- a/libcpp/macro.c ++++ b/libcpp/macro.c +@@ -181,7 +181,7 @@ class vaopt_state { + if (m_state == 2 && token->type == CPP_PASTE) + { + cpp_error_at (m_pfile, CPP_DL_ERROR, token->src_loc, +- vaopt_paste_error); ++ "%s", vaopt_paste_error); + return ERROR; + } + /* Advance states before further considering this token, in +@@ -210,7 +210,7 @@ class vaopt_state { + if (was_paste) + { + cpp_error_at (m_pfile, CPP_DL_ERROR, token->src_loc, +- vaopt_paste_error); ++ "%s", vaopt_paste_error); + return ERROR; + } + +@@ -3487,7 +3487,7 @@ create_iso_definition (cpp_reader *pfile) + function-like macros, but not at the end. */ + if (following_paste_op) + { +- cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg); ++ cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg); + goto out; + } + if (!vaopt_tracker.completed ()) +@@ -3502,7 +3502,7 @@ create_iso_definition (cpp_reader *pfile) + function-like macros, but not at the beginning. */ + if (macro->count == 1) + { +- cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg); ++ cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg); + goto out; + } + +-- +2.31.1 + diff --git a/PKGBUILD b/PKGBUILD index ad8fe43..3e07030 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -27,6 +27,7 @@ source=(https://sourceware.org/pub/gcc/releases/gcc-${pkgver}/gcc-${pkgver}.tar. fs64270.patch ipa-fix-bit-CPP-when-combined-with-IPA-bit-CP.patch ipa-fix-ICE-in-get_default_value.patch + 0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch ) validpgpkeys=(F3691687D867B81B51CE07D9BBE43771487328A9 # bpiotrowski@archlinux.org 86CFFCA918CF3AF47147588051E8B148A9999C34 # evangelos@foutrelis.com @@ -40,7 +41,8 @@ sha256sums=('b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c' 'c86372c207d174c0918d4aedf1cb79f7fc093649eb1ad8d9450dccc46849d308' '1ef190ed4562c4db8c1196952616cd201cfdd788b65f302ac2cc4dabb4d72cee' 'fcb11c9bcea320afd202b031b48f8750aeaedaa4b0c5dddcd2c0a16381e927e4' - '42865f2af3f48140580c4ae70b6ea03b5bdca0f29654773ef0d42ce00d60ea16') + '42865f2af3f48140580c4ae70b6ea03b5bdca0f29654773ef0d42ce00d60ea16' + 'd2a690a49f1cb38562c09466d73511775e4e8bc5e268b63b7486f670686cf68a') prepare() { [[ ! -d gcc ]] && ln -s gcc-${pkgver/+/-} gcc @@ -70,6 +72,7 @@ prepare() { # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96482 patch -Np1 -i ../ipa-fix-bit-CPP-when-combined-with-IPA-bit-CP.patch patch -Np1 -i ../ipa-fix-ICE-in-get_default_value.patch + patch -p 1 -i "${srcdir}"/0001-Fix-Wformat-security-warnings-in-libcpp-expr.c-macro.patch mkdir -p "$srcdir/gcc-build" } @@ -111,6 +114,7 @@ build() { --disable-libstdcxx-pch \ --disable-libunwind-exceptions \ --disable-werror \ + --enable-build-format-warnings \ gdc_include_dir=/usr/include/dlang/gdc make -- 2.31.1