Skip to contentSkip to conversation

Check for errors in the return value of GetModuleFileNameW()

PATCH In review [email protected]... 2 participants 2 messages May 14, 2017 – May 18, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check for errors in the return value of GetModuleFileNameW()

From: Selva Nair <[email protected]...>

Also replace MAX_PATH by _countof(openvpnpath) as the latter is arguably more robust.

---
 src/openvpn/win32.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/openvpn/win32.c +6 -1
index b271597..56c3a1d 100644
@@ -1271,7 +1271,12 @@ win_wfp_block_dns (const NET_IFINDEX index)
     dmsg (D_LOW, "Tap Luid: %I64d", tapluid.Value);
 
     /* Get OpenVPN path. */
-    GetModuleFileNameW(NULL, openvpnpath, MAX_PATH);
+    status = GetModuleFileNameW(NULL, openvpnpath, _countof(openvpnpath));
+    if (status == 0 || status == _countof(openvpnpath))
+    {
+        msg(M_WARN|M_ERRNO, "block_dns: failed to get executable path");
+        goto err;
+    }
 
     if (FwpmGetAppIdFromFileName0(openvpnpath, &openvpnblob) != ERROR_SUCCESS)
         goto err;
Signature · 1 line
2.1.4
#1 lore raw

ACK, thanks. This brings 2.3 in line with 2.4/master, which is good :-)

Your patch has been applied to the release/2.3 branch.

commit c18802e2e2c5b156d1b40dab255cea273131a96c

Author: Selva Nair
Date:   Sun May 14 18:16:36 2017 -0400
     Check for errors in the return value of GetModuleFileNameW()

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg14654.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering