[PATCH 5/5] trace-cmd: BUG fix malloc() pointer validation

From: Federico Vaga
Date: Sun Apr 23 2017 - 06:33:43 EST


To reproduce the bug

mkdir /sys/kernel/debug/tracing/instances/test
./trace-cmd show -B test -s -f
Failed to allocate instance path snapshot

Signed-off-by: Federico Vaga <federico.vaga@xxxxxxxxxx>
---
trace-cmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/trace-cmd.c b/trace-cmd.c
index a05df92..320229e 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -616,7 +616,7 @@ int main (int argc, char **argv)
if (buffer) {
path = malloc(strlen(buffer) + strlen("instances//") +
strlen(file) + 1);
- if (path)
+ if (!path)
die("Failed to allocate instance path %s", file);
sprintf(path, "instances/%s/%s", buffer, file);
file = path;
--
2.9.3