From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 3EA9138133E8 for ; Tue, 7 Jun 2022 14:50:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3EA9138133E8 Received: by mail-lj1-x22d.google.com with SMTP id v9so19469716lja.12 for ; Tue, 07 Jun 2022 07:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=evnW+UpIOjOEqTXWrNnj0ztIM8DodnfZ3+LiP+3SQxg=; b=irxSqok1wkLJkHPEnBL+CMJPksSbY2Nyv66/omfSt26H05/C07zpTk2MlC+IpXDJL/ fj4Tdl1ceHvhoINY0oC5rPIKNCnUN+FuMlFz8Tth4q3ht/R9ubhU2KuiSqHFYwo1wIQ4 c3ofLs0puLlwlBEGnHW8XE2Ma8YQAWA5OZn3nFokmr3/76aB8O2gTdcKdv3BdBqDw2ex PnMLOnJEPN+2G2SiwU01jc2B0B83iFhVmjaAmbIDta9elxak6vGAkZ9pLTIead5grJTs sl0J3L6yGgWaaOdJ3ayHNSJ7tXts41A1OdFYWl/9aEZymvIgVeHeGP+KErw5CrXuQFQS kMvg== X-Gm-Message-State: AOAM533gke7gwN1H08rTaMNbXur6z+PVNu4sGCuNSclD/QHm3nYOzDLx T4YL4Aq5XyP3bjic3JOkEBpufe4ECFeK9FN9jLOS1siSfShGdg== X-Google-Smtp-Source: ABdhPJycsfG4u59y0S78V0ym+/rN2/GyWYHeHQZKYGnsOhgQOmfx4pTo5Y3LLOG/BtY8fIzl8l7vU1Mnv0QkRTlHHA8= X-Received: by 2002:a2e:b0fc:0:b0:255:6f92:f9d4 with SMTP id h28-20020a2eb0fc000000b002556f92f9d4mr16750912ljl.92.1654613401867; Tue, 07 Jun 2022 07:50:01 -0700 (PDT) MIME-Version: 1.0 From: Yichao Yu Date: Tue, 7 Jun 2022 10:49:50 -0400 Message-ID: Subject: Werror=format-security issue from gprofng/src/Print.cc To: gdb@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2022 14:50:06 -0000 I got a format-security werror on gprofng/src/Print.cc when trying to build the master version of gdb (the compiler flag is added by the archlinuxcn build machine). While I could disable the flag, I think there might be a real issue looking at the code. The line that causes the issue is https://github.com/bminor/binutils-gdb/blob/master/gprofng/src/Print.cc#L2616, which uses a "dynamic" format string without any argument. AFAICT, the fmt3 is only ever initialized in `er_print_experiment::overview_summary` and if I read it correctly, it's initialized to a string with no actual formatting inputs other than a `%%`. It is used, however, twice in `er_print_experiment::overview_value`, one given two zeros as the arguments and one given no arguments so it looks a bit suspicious. The git log shows now history of this file so I'm not sure what's the intention but my best guess is 1. the `fprintf (out_file, fmt3, 0., 0.);` was meant to be using `fmt4`. (I assume this is to avoid nan from total_value = 0), or 2. since fmt3 is actually a string that's more or less "0.0 (0.0)" with padding, the two `0.`s passed to fmt3 are probably bogus and it should be the same as the `fprintf (out_file, fmt3);` below if my understanding is correct, I think in either case one can simply avoid using fmt3 with fprintf by just removing the extra % from it and directly write it to the output instead. (i.e. https://gist.github.com/yuyichao/7e7cc2f240a1a6e92a1b2a9da8eb3905) Did I miss anything? Yichao