]> granicus.if.org Git - procps-ng/commitdiff
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>
Fri, 18 May 2018 21:32:21 +0000 (07:32 +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 1a5b3e031c1e9b9f575c37e0378f2979536ed347..40ec787da17ade685138a6382286bee8fa0ef70e 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -131,13 +131,15 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd,
        char dn_buf[1000];
        dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV);
        if (run_time->interactive) {
-               char *buf;
+               char *buf = NULL;
                size_t len = 0;
                fprintf(stderr, "%-8s %-8s %5d %-16.16s   ? ",
                        (char *)dn_buf, pwcache_get_user(uid), pid, cmd);
                fflush (stdout);
-               if (getline(&buf, &len, stdin) == -1)
+               if (getline(&buf, &len, stdin) == -1) {
+                       free(buf);
                        return;
+               }
                if (rpmatch(buf) < 1) {
                        free(buf);
                        return;