chiark / gitweb /
process-util: fix two bugs in get_process_cmdline() (#3555)
authorLennart Poettering <lennart@poettering.net>
Thu, 16 Jun 2016 20:46:44 +0000 (22:46 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 16 Jun 2017 08:13:01 +0000 (10:13 +0200)
See:

https://github.com/elogind/elogind/pull/3529#issuecomment-226421007

src/basic/process-util.c

index dd77df2..5bf0a18 100644 (file)
@@ -160,6 +160,8 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
 
                 if (len > 0)
                         r[len] = 0;
+                else
+                        r = mfree(r);
 
         } else {
                 bool dotdotdot = false;
@@ -213,7 +215,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
                         }
 
                         strncpy(k, "...", left-1);
-                        k[left] = 0;
+                        k[left-1] = 0;
                 } else
                         *k = 0;
         }