[Openvpn-devel,v2] src/openvpn/dco_freebsd.c: handle malloc failure

Message ID 20230518212139.1261-1-chipitsine@gmail.com
State Accepted
Headers show
Series [Openvpn-devel,v2] src/openvpn/dco_freebsd.c: handle malloc failure | expand

Commit Message

Ilya Shipitsin May 18, 2023, 9:21 p.m. UTC
malloc was not checked against NULL, I was able
to get core dump in case of failure

Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
---
v2:
 - style correction

 src/openvpn/dco_freebsd.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Gert Doering May 19, 2023, 6:31 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

As discussed.

Tested with a basic client run on FreeBSD14 with DCO.

Your patch has been applied to the master and release/2.6 branch.

commit 5e79aed439d4e1b101c768aabfd695cd1c0a54ce (master)
commit 73ce6ac984e3ab496f97979e41f2a27569a432fd (release/2.6)
Author: Ilya Shipitsin
Date:   Thu May 18 23:21:39 2023 +0200

     src/openvpn/dco_freebsd.c: handle malloc failure

     Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20230518212139.1261-1-chipitsine@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26707.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 1111abeb..af7776bb 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -594,6 +594,10 @@  dco_available(int msglevel)
     }
 
     buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
+    if (!buf)
+    {
+        goto out;
+    }
 
     ifcr.ifcr_count = ifcr.ifcr_total;
     ifcr.ifcr_buffer = buf;