Am 17.05.23 um 22:47 schrieb Antonio Quartulli:
Hi,

On 17/05/2023 22:01, Ilya Shipitsin wrote:
malloc was not checked against NULL, I was able
to get core dump in case of failure

Signed-off-by: Ilya Shipitsin <chipits...@gmail.com>
---
  src/openvpn/dco_freebsd.c | 5 +++++
  1 file changed, 5 insertions(+)

diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
index 1111abeb..adbd1120 100644
--- a/src/openvpn/dco_freebsd.c
+++ b/src/openvpn/dco_freebsd.c
@@ -594,6 +594,11 @@ dco_available(int msglevel)
      }
        buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
+    if (buf == NULL)

as style guideline, we wanted to go for if (!A) rather than if (A ==
NULL). Although I am not sure if the whole codebase was cleaned up yet
or not.

That, and constants usually go on the left-hand side of comparison so
the compiler flags the accidental if (foo = NULL) even if it does not
produce "add a pair of parentheses if you really mean to use an
assignment as if() expression" like warnings. You can't if (NULL = foo)...

And in practice, if anyone hits C++ some day, it might make a difference
if you're in boolean or pointer contexts, so use if (!A).




_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to