]> granicus.if.org Git - procps-ng/commitdiff
0023-skill: Fix getline() usage.
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Jun 2018 11:59:14 +0000 (21:59 +1000)
man getline: "If *lineptr is set to NULL and *n is set 0 before the
call, then getline() will allocate a buffer for storing the line. This
buffer should be freed by the user program even if getline() failed."

skill.c

diff --git a/skill.c b/skill.c
index 88c2fdf8c724e864b124f45a149fbad057844877..2b7eb575c89a02b6764f34817855bc47414d9b32 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -178,8 +178,10 @@ static int ask_user(struct pids_stack *stack)
             PIDS_GETINT(PID),
             PIDS_GETSTR(CMD));
     fflush(stdout);
-    if (getline(&buf, &len, stdin) == -1)
+    if (getline(&buf, &len, stdin) == -1) {
+        free(buf);
         return 0;
+    }
     if (rpmatch(buf) < 1) {
         free(buf);
         return 0;