Skip to contentSkip to conversation

perf daemon: Fix compile error with Asan

PATCH Applied Namhyung Kim 3 participants 3 messages Feb 24, 2021 – Mar 3, 2021 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf daemon: Fix compile error with Asan

I'm seeing a build failure when build with address sanitizer. It seems we could write to the name[100] if the var is longer.

  $ make EXTRA_CFLAGS=-fsanitize=address
  ...
    CC       builtin-daemon.o
  In function ‘get_session_name’,
    inlined from ‘session_config’ at builtin-daemon.c:164:6,
    inlined from ‘server_config’ at builtin-daemon.c:223:10:
  builtin-daemon.c:155:11: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
    155 |  *session = 0;
        |  ~~~~~~~~~^~~
  builtin-daemon.c: In function ‘server_config’:
  builtin-daemon.c:162:7: note: at offset 100 to object ‘name’ with size 100 declared here
    162 |  char name[100];
        |       ^~~~
Fixes c0666261ff38 ("perf daemon: Add config file support")
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-daemon.c +1 -1
index 617feaf020f6..8f9fc61691da 100644
@@ -161,7 +161,7 @@ static int session_config(struct daemon *daemon, const char *var, const char *va
 	struct daemon_session *session;
 	char name[100];
 
-	if (get_session_name(var, name, sizeof(name)))
+	if (get_session_name(var, name, sizeof(name) - 1))
 		return -EINVAL;
 
 	var = strchr(var, '.');
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Namhyung Kim

I'm seeing a build failure when build with address sanitizer. It seems we could write to the name[100] if the var is longer.

  $ make EXTRA_CFLAGS=-fsanitize=address
  ...
    CC       builtin-daemon.o
  In function ‘get_session_name’,
    inlined from ‘session_config’ at builtin-daemon.c:164:6,
    inlined from ‘server_config’ at builtin-daemon.c:223:10:
  builtin-daemon.c:155:11: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
    155 |  *session = 0;
        |  ~~~~~~~~~^~~
  builtin-daemon.c: In function ‘server_config’:
  builtin-daemon.c:162:7: note: at offset 100 to object ‘name’ with size 100 declared here
    162 |  char name[100];
        |       ^~~~
Quoted 2 lines
Fixes c0666261ff38 ("perf daemon: Add config file support")

thanks,
jirka

Quoted 20 lines
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-daemon.c +1 -1
index 617feaf020f6..8f9fc61691da 100644
@@ -161,7 +161,7 @@ static int session_config(struct daemon *daemon, const char *var, const char *va
 	struct daemon_session *session;
 	char name[100];
 
-	if (get_session_name(var, name, sizeof(name)))
+	if (get_session_name(var, name, sizeof(name) - 1))
 		return -EINVAL;
 
 	var = strchr(var, '.');
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
maintainer Applied
#2 lore raw

Em Wed, Feb 24, 2021 at 12:06:46PM +0100, Jiri Olsa escreveu:

Quoted 18 lines · Namhyung Kim
Quoted 17 lines

I'm seeing a build failure when build with address sanitizer. It seems we could write to the name[100] if the var is longer.

  $ make EXTRA_CFLAGS=-fsanitize=address
  ...
    CC       builtin-daemon.o
  In function ‘get_session_name’,
    inlined from ‘session_config’ at builtin-daemon.c:164:6,
    inlined from ‘server_config’ at builtin-daemon.c:223:10:
  builtin-daemon.c:155:11: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
    155 |  *session = 0;
        |  ~~~~~~~~~^~~
  builtin-daemon.c: In function ‘server_config’:
  builtin-daemon.c:162:7: note: at offset 100 to object ‘name’ with size 100 declared here
    162 |  char name[100];
        |       ^~~~
Quoted 4 lines
Quoted 2 lines
Fixes c0666261ff38 ("perf daemon: Add config file support")

Thanks, applied.

- Arnaldo

Quoted 24 lines

thanks,
jirka

Quoted 20 lines
---
 tools/perf/builtin-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-daemon.c +1 -1
index 617feaf020f6..8f9fc61691da 100644
@@ -161,7 +161,7 @@ static int session_config(struct daemon *daemon, const char *var, const char *va
 	struct daemon_session *session;
 	char name[100];
 
-	if (get_session_name(var, name, sizeof(name)))
+	if (get_session_name(var, name, sizeof(name) - 1))
 		return -EINVAL;
 
 	var = strchr(var, '.');
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
Signature · 1 line
- Arnaldo