Skip to contentSkip to conversation

trace-cmd: Fixed a potential problem with non-terminated string, returned by readlink()

PATCH In review [email protected] 2 participants 2 messages Jul 3, 2019 – Jul 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Fixed a potential problem with non-terminated string, returned by readlink()

From: "Tzvetomir Stoyanov (VMware)" <[email protected]>

The buffer, returned by readlink() API, is not guaranteed to be a null terminated string. Explicitly adding '\0' at the end of the buffer is recommended, to ensure the string is null terminated and to avoid possible buffer overruns.

---
 lib/trace-cmd/trace-util.c | 1 +
 1 file changed, 1 insertion(+)
lib/trace-cmd/trace-util.c +1 -0
index 190cf74..7c74bae 100644
@@ -1373,6 +1373,7 @@ static char *trace_util_get_source_plugins_dir(void)
 	ret = readlink("/proc/self/exe", path, PATH_MAX);
 	if (ret > PATH_MAX || ret < 0)
 		return NULL;
+	path[ret] = 0;
 
 	dirname(path);
 	p = strrchr(path, '/');
Signature · 1 line
2.21.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 17 lines · On 3.07.19 г. 15:16 ч., [email protected] wrote:

From: "Tzvetomir Stoyanov (VMware)" <[email protected]>

The buffer, returned by readlink() API, is not guaranteed to be a null terminated string. Explicitly adding '\0' at the end of the buffer is recommended, to ensure the string is null terminated and to avoid possible buffer overruns.

---
  lib/trace-cmd/trace-util.c | 1 +
  1 file changed, 1 insertion(+)
lib/trace-cmd/trace-util.c +0 -0
index 190cf74..7c74bae 100644

lib/trace-cmd/trace-util.c static char *trace_util_get_source_plugins_dir(void) · line 1379

Quoted 7 lines
lib/trace-cmd/trace-util.c +1 -0
@@ -1373,6 +1373,7 @@ static char *trace_util_get_source_plugins_dir(void)
  	ret = readlink("/proc/self/exe", path, PATH_MAX);
  	if (ret > PATH_MAX || ret < 0)
  		return NULL;
+	path[ret] = 0;
 
  	dirname(path);
  	p = strrchr(path, '/');

Thanks!