]> granicus.if.org Git - psmisc/commitdiff
peekfd: Check return value of malloc
authorCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 11:08:27 +0000 (22:08 +1100)
committerCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 11:08:27 +0000 (22:08 +1100)
If malloc returned null on lastbuf then we would have had a
derefencing NULL issue.

References:
 Coverity 46258

src/peekfd.c

index f41391a2ecbaaff989fe796e66d600316ce1ef90..360b2f70439acaacfc032088efc52feee29baeab 100644 (file)
@@ -415,7 +415,8 @@ int main(int argc, char **argv)
                                                if (remove_duplicates) {
                                                        if (lastbuf)
                                                                free(lastbuf);
-                                                       lastbuf = malloc(regs.REG_PARAM3);
+                                                       if ( NULL == (lastbuf = malloc(regs.REG_PARAM3)))
+                                                           perror("lastbuf malloc");
                                                        last_buf_size = regs.REG_PARAM3;
                                                }