[05/10] batctl: Handle nl_socket_alloc errors

Message ID 20171123140444.17119-6-sven.eckelmann@openmesh.com (mailing list archive)
State Accepted, archived
Commit bc6cd37e0d3ce08e3b89e3123ffa87dc55f24c09
Delegated to: Simon Wunderlich
Headers
Series batctl: Fixes and minor cleanup |

Commit Message

Sven Eckelmann Nov. 23, 2017, 2:04 p.m. UTC
  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(+)
  

Patch

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);