batctl: Merge bugfixes from v2017.4
[feed/routing.git] / batctl / patches / 0008-batctl-Handle-nl_cb_alloc-errors.patch
1 From: Sven Eckelmann <sven.eckelmann@openmesh.com>
2 Date: Thu, 23 Nov 2017 15:04:40 +0100
3 Subject: [PATCH] batctl: Handle nl_cb_alloc errors
4
5 nl_cb_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/0a14f8800dac67d706827e9be7745e2319f5412c
13 ---
14 netlink.c | 17 ++++++++++++++++-
15 1 file changed, 16 insertions(+), 1 deletion(-)
16
17 diff --git a/netlink.c b/netlink.c
18 index 107ca52a4866e25b7b04428d770a885ca4e826d2..3eb66c9de30c21722bb1e348b055838ea14d18cf 100644
19 --- a/netlink.c
20 +++ b/netlink.c
21 @@ -320,11 +320,15 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header)
22 nlmsg_free(msg);
23
24 cb = nl_cb_alloc(NL_CB_DEFAULT);
25 + if (!cb)
26 + goto err_free_sock;
27 +
28 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, info_callback, &opts);
29 nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL);
30
31 nl_recvmsgs(sock, cb);
32
33 +err_free_sock:
34 nl_socket_free(sock);
35
36 return opts.remaining_header;
37 @@ -425,6 +429,11 @@ int netlink_print_routing_algos(void)
38 opts.remaining_header = strdup("Available routing algorithms:\n");
39
40 cb = nl_cb_alloc(NL_CB_DEFAULT);
41 + if (!cb) {
42 + last_err = -ENOMEM;
43 + goto err_free_sock;
44 + }
45 +
46 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb,
47 &opts);
48 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, stop_callback, NULL);
49 @@ -1134,9 +1143,14 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
50 }
51 }
52
53 + cb = nl_cb_alloc(NL_CB_DEFAULT);
54 + if (!cb) {
55 + last_err = -ENOMEM;
56 + goto err_free_sock;
57 + }
58 +
59 bat_hosts_init(read_opt);
60
61 - cb = nl_cb_alloc(NL_CB_DEFAULT);
62 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb, &opts);
63 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, stop_callback, NULL);
64 nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL);
65 @@ -1181,6 +1195,7 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
66
67 bat_hosts_free();
68
69 +err_free_sock:
70 nl_socket_free(sock);
71
72 return last_err;