]> prime8.dev >> repos - ttyd.git/commitdiff
Add the missing null terminator to command string
authorShuanglei Tao <tsl0922@gmail.com>
Tue, 21 Mar 2017 15:06:57 +0000 (23:06 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Tue, 21 Mar 2017 15:07:13 +0000 (23:07 +0800)
src/server.c

index e7a714425dd32690c431afceb11097987c1dc147..2856db0b4f7724bb051cc94455f90c1087a519da 100644 (file)
@@ -107,14 +107,15 @@ tty_server_new(int argc, char **argv, int start) {
     }
     ts->argv[cmd_argc] = NULL;
 
-    ts->command = xmalloc(cmd_len);
+    ts->command = xmalloc(cmd_len + 1);
     char *ptr = ts->command;
     for (int i = 0; i < cmd_argc; i++) {
         ptr = stpcpy(ptr, ts->argv[i]);
         if (i != cmd_argc - 1) {
-            sprintf(ptr++, "%c", ' ');
+            *ptr++ = ' ';
         }
     }
+    *ptr = '\0'; // null terminator
 
     return ts;
 }