batctl: Merge bugfixes from v2017.4
[feed/routing.git] / batctl / patches / 0006-batctl-Handle-nlmsg_alloc-errors.patch
1 From: Sven Eckelmann <sven.eckelmann@openmesh.com>
2 Date: Thu, 23 Nov 2017 15:04:38 +0100
3 Subject: [PATCH] batctl: Handle nlmsg_alloc errors
4
5 nlmsg_alloc may return NULL on errors. The processing has to be aborted
6 when this happens.
7
8 Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
9 Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
10 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
11
12 Origin: upstream, https://git.open-mesh.org/batctl.git/commit/27e9937635ffbfe33f7f3297aff911718b8deb56
13 ---
14 netlink.c | 15 +++++++++++++++
15 1 file changed, 15 insertions(+)
16
17 diff --git a/netlink.c b/netlink.c
18 index 5f4325b0bb6b4a41860a75bd0851e446c5af9a88..64afeedac46bf3eab14a1d89d7db4491fbef8d81 100644
19 --- a/netlink.c
20 +++ b/netlink.c
21 @@ -302,6 +302,11 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header)
22 return NULL;
23
24 msg = nlmsg_alloc();
25 + if (!msg) {
26 + nl_socket_free(sock);
27 + return NULL;
28 + }
29 +
30 genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0,
31 BATADV_CMD_GET_MESH_INFO, 1);
32
33 @@ -399,6 +404,11 @@ int netlink_print_routing_algos(void)
34 return -EOPNOTSUPP;
35
36 msg = nlmsg_alloc();
37 + if (!msg) {
38 + last_err = -ENOMEM;
39 + goto err_free_sock;
40 + }
41 +
42 genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_DUMP,
43 BATADV_CMD_GET_ROUTING_ALGOS, 1);
44
45 @@ -415,6 +425,8 @@ int netlink_print_routing_algos(void)
46 nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL);
47
48 nl_recvmsgs(sock, cb);
49 +
50 +err_free_sock:
51 nl_socket_free(sock);
52
53 if (!last_err)
54 @@ -1131,6 +1143,9 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
55 header);
56
57 msg = nlmsg_alloc();
58 + if (!msg)
59 + continue;
60 +
61 genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0,
62 NLM_F_DUMP, nl_cmd, 1);
63