Skip to contentSkip to conversation

perf build-id: Fix filename size calculation

PATCH Applied Namhyung Kim 2 participants 3 messages May 1, 2012 – May 3, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf build-id: Fix filename size calculation

The filename is a pointer variable so the sizeof(filename) will return length of a pointer. Fix it by using 'size'.

---
 tools/perf/util/header.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/header.c +1 -1
index 4c7c2d73251f..c0b70c697a36 100644
@@ -296,7 +296,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
 	if (mkdir_p(filename, 0755))
 		goto out_free;
 
-	snprintf(filename + len, sizeof(filename) - len, "/%s", sbuild_id);
+	snprintf(filename + len, size - len, "/%s", sbuild_id);
 
 	if (access(filename, F_OK)) {
 		if (is_kallsyms) {
Signature · 1 line
1.7.9.2
#1 lore raw
Commit-ID:  afda0f94483f46a4caddb529b8f95e0aaf015de6
Gitweb:     http://git.kernel.org/tip/afda0f94483f46a4caddb529b8f95e0aaf015de6
Author:     Namhyung Kim <[email protected]>
AuthorDate: Tue, 1 May 2012 23:19:36 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 1 May 2012 14:13:00 -0300

perf build-id: Fix filename size calculation

The filename is a pointer variable so the sizeof(filename) will return length of a pointer. Fix it by using 'size'.

---
 tools/perf/util/header.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/header.c +1 -1
index 4c7c2d7..c0b70c6 100644
@@ -296,7 +296,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
 	if (mkdir_p(filename, 0755))
 		goto out_free;
 
-	snprintf(filename + len, sizeof(filename) - len, "/%s", sbuild_id);
+	snprintf(filename + len, size - len, "/%s", sbuild_id);
 
 	if (access(filename, F_OK)) {
 		if (is_kallsyms) {
#2 lore raw
In reply to Namhyung Kim

Em Tue, May 01, 2012 at 11:19:36PM +0900, Namhyung Kim escreveu:

Quoted 2 lines

The filename is a pointer variable so the sizeof(filename) will return length of a pointer. Fix it by using 'size'.

Applied.

The code worked because the snprintf buffer size parameter would always be bigger (negative) than the sbuild_id lenght, and all fitted in the filename allocated space. :-)

- Arnaldo

Quoted 20 lines
---
 tools/perf/util/header.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/header.c +1 -1
index 4c7c2d73251f..c0b70c697a36 100644
@@ -296,7 +296,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
 	if (mkdir_p(filename, 0755))
 		goto out_free;
 
-	snprintf(filename + len, sizeof(filename) - len, "/%s", sbuild_id);
+	snprintf(filename + len, size - len, "/%s", sbuild_id);
 
 	if (access(filename, F_OK)) {
 		if (is_kallsyms) {
Signature · 1 line
1.7.9.2