[Openvpn-devel] Fix missing check for return value of malloc'd buffer

Message ID 1508094315-466-1-git-send-email-selva.nair@gmail.com
State Accepted
Headers show
Series
  • [Openvpn-devel] Fix missing check for return value of malloc'd buffer
Related show

Commit Message

Selva Nair Oct. 15, 2017, 7:05 p.m.
From: Selva Nair <selva.nair@gmail.com>

- Use utf8to16 from common.c for utf8 to wide conversion and
  check its return value

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
 src/openvpnserv/interactive.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Comments

Gert Doering Nov. 3, 2017, 6:54 p.m. | #1
ACK.

Patch is actually fairly trivial as soon as one recognizes that 
"utf8to16()" is one of our functions, which does exactly what the
code removed here does - length check, malloc, malloc check, 
conversion-if-memory-allocated.

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

commit f3d389a2d2b87aeb649bfdccd596f485346a32c7 (master)
commit 9ef03874bf0ca35348c58b4b21cb06cc49026efd (release/2.4)
Author: Selva Nair
Date:   Sun Oct 15 15:05:15 2017 -0400

     Fix missing check for return value of malloc'd buffer

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <1508094315-466-1-git-send-email-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15641.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Patch

diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index 3f98217..f3be113 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -547,15 +547,17 @@  static DWORD
 InterfaceLuid(const char *iface_name, PNET_LUID luid)
 {
     NETIO_STATUS status;
-    LPWSTR wide_name;
-    int n;
-
-    n = MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, NULL, 0);
-    wide_name = malloc(n * sizeof(WCHAR));
-    MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, wide_name, n);
-    status = ConvertInterfaceAliasToLuid(wide_name, luid);
-    free(wide_name);
+    LPWSTR wide_name = utf8to16(iface_name);
 
+    if (wide_name)
+    {
+        status = ConvertInterfaceAliasToLuid(wide_name, luid);
+        free(wide_name);
+    }
+    else
+    {
+        status = ERROR_OUTOFMEMORY;
+    }
     return status;
 }