psmisc/backport-0005-peekfd-Check-return-value-of-malloc.patch

33 lines
931 B
Diff
Raw Normal View History

2020-11-03 14:21:18 +08:00
From edad7cd77c5b95db2f7fe4e3678e7444a1bcc399 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@dropbear.xyz>
Date: Mon, 2 Mar 2020 22:08:27 +1100
Subject: [PATCH 11/20] peekfd: Check return value of malloc
If malloc returned null on lastbuf then we would have had a
derefencing NULL issue.
References:
Coverity 46258
https://gitlab.com/psmisc/psmisc/-/commit/edad7cd77c5b95db2f7fe4e3678e7444a1bcc399
---
src/peekfd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/peekfd.c b/src/peekfd.c
index f41391a..360b2f7 100644
--- a/src/peekfd.c
+++ b/src/peekfd.c
@@ -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;
}
--
2.22.0.windows.1