aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2011-05-10 00:24:53 +0300
committerArjan van de Ven <arjan@linux.intel.com>2011-05-11 00:04:35 -0400
commit8287da740543f797d5ce39870c0bca81d27b46a3 (patch)
tree15d8e1168f0635cd57a9e7219bacbcef7278c93b
parente1dc44b884c799ce069f7e7d76e5bfb44365e5b7 (diff)
downloadpowertop-8287da740543f797d5ce39870c0bca81d27b46a3.tar.gz
null-terminate process's description when cmdline is too big
Process's cmdline could be bigger than desc[256]. In that case we'll have non-null-terminated desc string after strncpy. Null-terminate it explicitly. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
-rw-r--r--process/process.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/process/process.cpp b/process/process.cpp
index 024f613..549fc87 100644
--- a/process/process.cpp
+++ b/process/process.cpp
@@ -131,8 +131,10 @@ process::process(const char *_comm, int _pid, int _tid) : power_consumer()
is_kernel = 1;
sprintf(desc, "[%s]", comm);
} else {
+ int sz = sizeof(desc) - 1;
cmdline_to_string(line);
- strncpy(desc, line, sizeof(desc) - 1);
+ strncpy(desc, line, sz);
+ desc[sz] = 0x00;
}
}
}