b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@openmesh.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven.eckelmann@openmesh.com>
Subject: [B.A.T.M.A.N.] [PATCH 06/10] batctl: Handle nl_cb_alloc errors
Date: Thu, 23 Nov 2017 15:04:40 +0100	[thread overview]
Message-ID: <20171123140444.17119-7-sven.eckelmann@openmesh.com> (raw)
In-Reply-To: <20171123140444.17119-1-sven.eckelmann@openmesh.com>

nl_cb_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 | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/netlink.c b/netlink.c
index d7aeb9a..b95063a 100644
--- a/netlink.c
+++ b/netlink.c
@@ -320,11 +320,15 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header)
 	nlmsg_free(msg);
 
 	cb = nl_cb_alloc(NL_CB_DEFAULT);
+	if (!cb)
+		goto err_free_sock;
+
 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, info_callback, &opts);
 	nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL);
 
 	nl_recvmsgs(sock, cb);
 
+err_free_sock:
 	nl_socket_free(sock);
 
 	return opts.remaining_header;
@@ -425,6 +429,11 @@ int netlink_print_routing_algos(void)
 	opts.remaining_header = strdup("Available routing algorithms:\n");
 
 	cb = nl_cb_alloc(NL_CB_DEFAULT);
+	if (!cb) {
+		last_err = -ENOMEM;
+		goto err_free_sock;
+	}
+
 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb,
 		  &opts);
 	nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, stop_callback, NULL);
@@ -1134,9 +1143,14 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
 		}
 	}
 
+	cb = nl_cb_alloc(NL_CB_DEFAULT);
+	if (!cb) {
+		last_err = -ENOMEM;
+		goto err_free_sock;
+	}
+
 	bat_hosts_init(read_opt);
 
-	cb = nl_cb_alloc(NL_CB_DEFAULT);
 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb, &opts);
 	nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, stop_callback, NULL);
 	nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL);
@@ -1181,6 +1195,7 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
 
 	bat_hosts_free();
 
+err_free_sock:
 	nl_socket_free(sock);
 
 	return last_err;
-- 
2.11.0


  parent reply	other threads:[~2017-11-23 14:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-23 14:04 [B.A.T.M.A.N.] [PATCH 00/10] batctl: Fixes and minor cleanup Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 01/10] batctl: Print dummy value when localtime failed Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 02/10] batctl: Handle failure during hash_iterator allocation Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 03/10] batctl: Handle allocation error for path_buff Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 04/10] batctl: Handle nlmsg_alloc errors Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 05/10] batctl: Handle nl_socket_alloc errors Sven Eckelmann
2017-11-23 14:04 ` Sven Eckelmann [this message]
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 07/10] batctl: Free nl_sock on genl_ctrl_resolve error Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 08/10] batctl: Free nl_sock when if_nametoindex failed Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 09/10] batctl: tcpdump: Fix types for for TT v1 Sven Eckelmann
2017-11-23 14:04 ` [B.A.T.M.A.N.] [PATCH 10/10] batctl: Simplify concatenation of pathnames Sven Eckelmann
2017-12-01 11:19 ` [B.A.T.M.A.N.] [PATCH 00/10] batctl: Fixes and minor cleanup Simon Wunderlich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171123140444.17119-7-sven.eckelmann@openmesh.com \
    --to=sven.eckelmann@openmesh.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).