pahole: Make sure the features string is NUL terminated
PATCH 1/1 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.
--- pahole.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
pahole.c +2 -2
@@ -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);
Signature · 1 line
2.43.0
Quoted 11 lines · Arnaldo Carvalho de Melo
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) $
Quoted 8 lines
When building in Release mode, for instance by using the
buildcmd.shscript.Cc Alan Maguire <[email protected]>Cc Eduard Zingerman <[email protected]>Fixes 7bc9b9975545ab53 ("pahole: Add --btf_features support")Signed-off-by Arnaldo Carvalho de Melo <[email protected]>---
Can confirm, warning is fixed by this patch.strncpy() API is not great :(
Quoted 11 lines · Arnaldo Carvalho de Melo
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) $
Quoted 8 lines
When building in Release mode, for instance by using the
buildcmd.shscript.Cc Alan Maguire <[email protected]>Cc Eduard Zingerman <[email protected]>Fixes 7bc9b9975545ab53 ("pahole: Add --btf_features support")Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Thanks for fixing this Arnaldo! I'll make sure to build in release mode in future.
---
Quoted 25 lines
pahole.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)pahole.c +2
-2@@ -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);