* [PATCH 1/1] perf machine: Use path__join() to compose a path instead of snprintf(dir, '/', filename)
@ 2022-01-18 15:13 Arnaldo Carvalho de Melo
2022-01-19 16:29 ` Ian Rogers
0 siblings, 1 reply; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-01-18 15:13 UTC (permalink / raw)
To: Jiri Olsa
Cc: Adrian Hunter, Ian Rogers, Namhyung Kim,
Linux Kernel Mailing List, linux-perf-users
Its more intention revealing, and if we're interested in the odd cases
where this may end up truncating we can do debug checks at one
centralized place.
Motivation, of all the container builds, fedora rawhide started
complaining of:
util/machine.c: In function ‘machine__create_modules’:
util/machine.c:1419:50: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
1419 | snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
| ^~
In file included from /usr/include/stdio.h:894,
from util/branch.h:9,
from util/callchain.h:8,
from util/machine.c:7:
In function ‘snprintf’,
inlined from ‘maps__set_modules_path_dir’ at util/machine.c:1419:3,
inlined from ‘machine__set_modules_path’ at util/machine.c:1473:9,
inlined from ‘machine__create_modules’ at util/machine.c:1519:7:
/usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 2 and 4352 bytes into a destination of size 4096
There are other places where we should use path__join(), but lets get rid of
this one first.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/machine.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3901440aeff92652..f70ba56912d4f9f8 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -16,6 +16,7 @@
#include "map_symbol.h"
#include "branch.h"
#include "mem-events.h"
+#include "path.h"
#include "srcline.h"
#include "symbol.h"
#include "sort.h"
@@ -1416,7 +1417,7 @@ static int maps__set_modules_path_dir(struct maps *maps, const char *dir_name, i
struct stat st;
/*sshfs might return bad dent->d_type, so we have to stat*/
- snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
+ path__join(path, sizeof(path), dir_name, dent->d_name);
if (stat(path, &st))
continue;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 1/1] perf machine: Use path__join() to compose a path instead of snprintf(dir, '/', filename)
2022-01-18 15:13 [PATCH 1/1] perf machine: Use path__join() to compose a path instead of snprintf(dir, '/', filename) Arnaldo Carvalho de Melo
@ 2022-01-19 16:29 ` Ian Rogers
0 siblings, 0 replies; 2+ messages in thread
From: Ian Rogers @ 2022-01-19 16:29 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, Adrian Hunter, Namhyung Kim, Linux Kernel Mailing List,
linux-perf-users
On Tue, Jan 18, 2022 at 7:13 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Its more intention revealing, and if we're interested in the odd cases
> where this may end up truncating we can do debug checks at one
> centralized place.
>
> Motivation, of all the container builds, fedora rawhide started
> complaining of:
>
> util/machine.c: In function ‘machine__create_modules’:
> util/machine.c:1419:50: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
> 1419 | snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
> | ^~
> In file included from /usr/include/stdio.h:894,
> from util/branch.h:9,
> from util/callchain.h:8,
> from util/machine.c:7:
> In function ‘snprintf’,
> inlined from ‘maps__set_modules_path_dir’ at util/machine.c:1419:3,
> inlined from ‘machine__set_modules_path’ at util/machine.c:1473:9,
> inlined from ‘machine__create_modules’ at util/machine.c:1519:7:
> /usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 2 and 4352 bytes into a destination of size 4096
>
> There are other places where we should use path__join(), but lets get rid of
> this one first.
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/machine.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 3901440aeff92652..f70ba56912d4f9f8 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -16,6 +16,7 @@
> #include "map_symbol.h"
> #include "branch.h"
> #include "mem-events.h"
> +#include "path.h"
> #include "srcline.h"
> #include "symbol.h"
> #include "sort.h"
> @@ -1416,7 +1417,7 @@ static int maps__set_modules_path_dir(struct maps *maps, const char *dir_name, i
> struct stat st;
>
> /*sshfs might return bad dent->d_type, so we have to stat*/
> - snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
> + path__join(path, sizeof(path), dir_name, dent->d_name);
> if (stat(path, &st))
> continue;
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-19 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-18 15:13 [PATCH 1/1] perf machine: Use path__join() to compose a path instead of snprintf(dir, '/', filename) Arnaldo Carvalho de Melo
2022-01-19 16:29 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).