diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-14 09:34:11 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-16 12:56:38 -0400 |
commit | 6810158d526e483868e519befff407b91e76b3db (patch) | |
tree | 50b13b179897171ea1098f4d0b24f3bfb275c192 /tools | |
parent | 10f354a36f9a9aa1b8bffe0abc1cd43822a85bcd (diff) |
perf annotate: Use asprintf when formatting objdump command line
We were using a local buffer with an arbitrary size, that would have to
get increased to avoid truncation as warned by gcc 8:
util/annotate.c: In function 'symbol__disassemble':
util/annotate.c:1488:4: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 3966 and 8086 [-Werror=format-truncation=]
"%s %s%s --start-address=0x%016" PRIx64
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util/annotate.c:1498:20:
symfs_filename, symfs_filename);
~~~~~~~~~~~~~~
util/annotate.c:1490:50: note: format string is defined here
" -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand",
^~
In file included from /usr/include/stdio.h:861,
from util/color.h:5,
from util/sort.h:8,
from util/annotate.c:14:
/usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 116 or more bytes (assuming 8331) into a destination of size 8192
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So switch to asprintf, that will make sure enough space is available.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-qagoy2dmbjpc9gdnaj0r3mml@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/annotate.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index bc3302da702b..ddad87f34a68 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -1427,7 +1427,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) | |||
1427 | { | 1427 | { |
1428 | struct map *map = args->map; | 1428 | struct map *map = args->map; |
1429 | struct dso *dso = map->dso; | 1429 | struct dso *dso = map->dso; |
1430 | char command[PATH_MAX * 2]; | 1430 | char *command; |
1431 | FILE *file; | 1431 | FILE *file; |
1432 | char symfs_filename[PATH_MAX]; | 1432 | char symfs_filename[PATH_MAX]; |
1433 | struct kcore_extract kce; | 1433 | struct kcore_extract kce; |
@@ -1468,7 +1468,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) | |||
1468 | strcpy(symfs_filename, tmp); | 1468 | strcpy(symfs_filename, tmp); |
1469 | } | 1469 | } |
1470 | 1470 | ||
1471 | snprintf(command, sizeof(command), | 1471 | err = asprintf(&command, |
1472 | "%s %s%s --start-address=0x%016" PRIx64 | 1472 | "%s %s%s --start-address=0x%016" PRIx64 |
1473 | " --stop-address=0x%016" PRIx64 | 1473 | " --stop-address=0x%016" PRIx64 |
1474 | " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand", | 1474 | " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand", |
@@ -1481,12 +1481,17 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) | |||
1481 | symbol_conf.annotate_src ? "-S" : "", | 1481 | symbol_conf.annotate_src ? "-S" : "", |
1482 | symfs_filename, symfs_filename); | 1482 | symfs_filename, symfs_filename); |
1483 | 1483 | ||
1484 | if (err < 0) { | ||
1485 | pr_err("Failure allocating memory for the command to run\n"); | ||
1486 | goto out_remove_tmp; | ||
1487 | } | ||
1488 | |||
1484 | pr_debug("Executing: %s\n", command); | 1489 | pr_debug("Executing: %s\n", command); |
1485 | 1490 | ||
1486 | err = -1; | 1491 | err = -1; |
1487 | if (pipe(stdout_fd) < 0) { | 1492 | if (pipe(stdout_fd) < 0) { |
1488 | pr_err("Failure creating the pipe to run %s\n", command); | 1493 | pr_err("Failure creating the pipe to run %s\n", command); |
1489 | goto out_remove_tmp; | 1494 | goto out_free_command; |
1490 | } | 1495 | } |
1491 | 1496 | ||
1492 | pid = fork(); | 1497 | pid = fork(); |
@@ -1513,7 +1518,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) | |||
1513 | * If we were using debug info should retry with | 1518 | * If we were using debug info should retry with |
1514 | * original binary. | 1519 | * original binary. |
1515 | */ | 1520 | */ |
1516 | goto out_remove_tmp; | 1521 | goto out_free_command; |
1517 | } | 1522 | } |
1518 | 1523 | ||
1519 | nline = 0; | 1524 | nline = 0; |
@@ -1541,6 +1546,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args) | |||
1541 | 1546 | ||
1542 | fclose(file); | 1547 | fclose(file); |
1543 | err = 0; | 1548 | err = 0; |
1549 | out_free_command: | ||
1550 | free(command); | ||
1544 | out_remove_tmp: | 1551 | out_remove_tmp: |
1545 | close(stdout_fd[0]); | 1552 | close(stdout_fd[0]); |
1546 | 1553 | ||
@@ -1554,7 +1561,7 @@ out: | |||
1554 | 1561 | ||
1555 | out_close_stdout: | 1562 | out_close_stdout: |
1556 | close(stdout_fd[1]); | 1563 | close(stdout_fd[1]); |
1557 | goto out_remove_tmp; | 1564 | goto out_free_command; |
1558 | } | 1565 | } |
1559 | 1566 | ||
1560 | static void calc_percent(struct sym_hist *hist, | 1567 | static void calc_percent(struct sym_hist *hist, |