summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-08-15 12:59:45 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-08-15 12:59:45 +0200
commitdf928892e8dd689416cab464cc05284997c0c188 (patch)
tree816a0e43895760532abf8bc213b0d9dd0e82db4d /slstatus.c
parent086a70cde0a887a55d5554109e483c19bc6ad8c2 (diff)
fixed strlen-bomb in run_command
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/slstatus.c b/slstatus.c
index 6ffc8e0..d993eca 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -453,6 +453,7 @@ ram_used(const char *null)
char *
run_command(const char* command)
{
+ int good;
FILE *fp;
char buffer[64];
@@ -469,7 +470,15 @@ run_command(const char* command)
pclose(fp);
/* add nullchar at the end */
- buffer[strlen(buffer) - 1] = '\0';
+ for (int i = 0 ; i != sizeof(buffer) ; i++) {
+ if (buffer[i] == '\0') {
+ good = 1;
+ break;
+ }
+ }
+ if (good) {
+ buffer[strlen(buffer) - 1] = '\0';
+ }
/* return the output */
return smprintf("%s", buffer);