[Openvpn-devel,v3] Add missing check for nl_socket_alloc failure

Message ID 20231121170603.886801-1-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel,v3] Add missing check for nl_socket_alloc failure | expand

Commit Message

Arne Schwabe Nov. 21, 2023, 5:06 p.m. UTC
This can happen if the memory alloc fails.

Patch V2: add goto error
Patch V3: return -ENOMEM instead of going to error

Change-Id: Iee66caa794d267ac5f8bee584633352893047171
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/dco_linux.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Antonio Quartulli Nov. 22, 2023, 12:35 p.m. UTC | #1
Hi,

On 21/11/2023 18:06, Arne Schwabe wrote:
> This can happen if the memory alloc fails.
> 
> Patch V2: add goto error
> Patch V3: return -ENOMEM instead of going to error
> 
> Change-Id: Iee66caa794d267ac5f8bee584633352893047171
> Signed-off-by: Arne Schwabe <arne@rfc2549.org>

Acked-by: Antonio Quartulli <a@unstable.cc>

> ---
>   src/openvpn/dco_linux.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c
> index b033f8543..3c91606b7 100644
> --- a/src/openvpn/dco_linux.c
> +++ b/src/openvpn/dco_linux.c
> @@ -81,6 +81,12 @@ resolve_ovpn_netlink_id(int msglevel)
>       int ret;
>       struct nl_sock *nl_sock = nl_socket_alloc();
>   
> +    if (!nl_sock)
> +    {
> +        msg(msglevel, "Allocating net link socket failed");
> +        return -ENOMEM;
> +    }
> +
>       ret = genl_connect(nl_sock);
>       if (ret)
>       {
Gert Doering Dec. 2, 2023, 3:58 p.m. UTC | #2
Took us long enough for such a simple fix... :-)

I have no easy way to trigger this, so only compile tested.

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

commit d1c31e428120bb0fc9488c62c1691c92a37d94c3 (master)
commit aa19a6a90f7ef24df12eed205663f3cfbb7d8174 (release/2.6)
Author: Arne Schwabe
Date:   Tue Nov 21 18:06:03 2023 +0100

     Add missing check for nl_socket_alloc failure

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Antonio Quartulli <antonio@openvpn.net>
     Message-Id: <20231121170603.886801-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27541.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c
index b033f8543..3c91606b7 100644
--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dco_linux.c
@@ -81,6 +81,12 @@  resolve_ovpn_netlink_id(int msglevel)
     int ret;
     struct nl_sock *nl_sock = nl_socket_alloc();
 
+    if (!nl_sock)
+    {
+        msg(msglevel, "Allocating net link socket failed");
+        return -ENOMEM;
+    }
+
     ret = genl_connect(nl_sock);
     if (ret)
     {