[B.A.T.M.A.N.] [PATCH 05/10] batctl: Handle nl_socket_alloc errors

Sven Eckelmann
2017-11-23T14:04:39Z

nl_socket_alloc may return NULL on errors. The processing has to be aborted
when this happens.

Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
---
netlink.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/netlink.c b/netlink.c
index e3d7892..d7aeb9a 100644
--- a/netlink.c
+++ b/netlink.c
@@ -295,6 +295,9 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header)
};

sock = nl_socket_alloc();
+ if (!sock)
+ return NULL;
+
genl_connect(sock);

family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
@@ -397,6 +400,9 @@ int netlink_print_routing_algos(void)
};

sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
genl_connect(sock);

family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
@@ -1104,6 +1110,9 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
int family;

sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
genl_connect(sock);

family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
--
2.11.0