aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2024-02-05 16:17:13 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2024-02-05 16:17:13 -0300
commitfdd815151054d840fe3bdc54f7ca79ff89fd4980 (patch)
tree0cb1770257cd289c9377515cba9cbc492640c1be
parent884c43ea82a154ce1970b02cd60f8e6602e562fc (diff)
downloadpahole-fdd815151054d840fe3bdc54f7ca79ff89fd4980.tar.gz
pahole: Make sure the features string is NUL terminated
To address this compiler warning: /home/acme/git/pahole/pahole.c: In function ‘parse_btf_features’: /home/acme/git/pahole/pahole.c:1353:9: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] 1353 | strncpy(f, features, sizeof(f)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $ gcc -v |& tail -1 gcc version 13.2.1 20231205 (Red Hat 13.2.1-6) (GCC) $ When building in Release mode, for instance by using the buildcmd.sh script. Cc: Alan Maguire <alan.maguire@oracle.com> Cc: Eduard Zingerman <eddyz87@gmail.com> Fixes: 7bc9b9975545ab53 ("pahole: Add --btf_features support") Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--pahole.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/pahole.c b/pahole.c
index 768a2feb..0e079ae1 100644
--- a/pahole.c
+++ b/pahole.c
@@ -1338,7 +1338,7 @@ static void show_supported_btf_features(FILE *output)
static void parse_btf_features(const char *features, bool strict)
{
char *saveptr = NULL, *s, *feature_name;
- char f[BTF_MAX_FEATURE_STR];
+ char f[BTF_MAX_FEATURE_STR + 1];
init_btf_features();
@@ -1350,7 +1350,7 @@ static void parse_btf_features(const char *features, bool strict)
return;
}
- strncpy(f, features, sizeof(f));
+ strncpy(f, features, BTF_MAX_FEATURE_STR)[BTF_MAX_FEATURE_STR] = '\0';
s = f;
while ((feature_name = strtok_r(s, ",", &saveptr)) != NULL) {
struct btf_feature *feature = find_btf_feature(feature_name);