Message ID | 20190703121644.18680-1-tz.stoyanov@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 7b0abc9a4168a8fe0a258e0ec76b3173215ab019 |
Headers | show |
Series | trace-cmd: Fixed a potential problem with non-terminated string, returned by readlink() | expand |
On 3.07.19 г. 15:16 ч., tz.stoyanov@gmail.com wrote: > From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> > > 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. > > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> > --- > lib/trace-cmd/trace-util.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c > index 190cf74..7c74bae 100644 > --- a/lib/trace-cmd/trace-util.c > +++ b/lib/trace-cmd/trace-util.c > @@ -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! Reviewed-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> Tested-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 190cf74..7c74bae 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -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, '/');