From patchwork Thu Nov 23 14:04:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17157 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 726298089C; Thu, 23 Nov 2017 15:05:56 +0100 (CET) Authentication-Results: open-mesh.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=openmesh-com.20150623.gappssmtp.com header.i=@openmesh-com.20150623.gappssmtp.com header.b="x8Y03jB2"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::242; helo=mail-qk0-x242.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x242.google.com (mail-qk0-x242.google.com [IPv6:2607:f8b0:400d:c09::242]) by open-mesh.org (Postfix) with ESMTPS id 42BB0806A5 for ; Thu, 23 Nov 2017 15:05:28 +0100 (CET) Received: by mail-qk0-x242.google.com with SMTP id o6so21081562qkh.3 for ; Thu, 23 Nov 2017 06:05:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openmesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b/GrD1ZMq5hGG9fulNDRZjySQhPsoU14exxeLnGeNAA=; b=x8Y03jB2rjiEnQJj7b2o2F1WJK96PgHlCMJkjiG6omSiwpzrbuZ7BU0z+QCCSCxwO7 mJ/XOkQein1GPkCH0+sHHu8+/BTguOMs6IFQM+/+99opMf6zfcNr0qh8gO0A+42Vh1H8 SrIikJTOOe203cbveu3RdkT1nYsFiHIHmZ0SP4i0JBXljln+Ssl1KswbsMS09GflcFdp DN/rkHVK6g2QLBoXLssccTu4Ivf40Z8KUStJQfF/vZFlYceZizN/4alMJRcDp3OSqjsJ YjrVIpMTqGDhz5DqbZi8Y+gbThUATuhH5iC+Dw3Wjiu45rerzSW2ldinfBiK6xU6MBVJ mLhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b/GrD1ZMq5hGG9fulNDRZjySQhPsoU14exxeLnGeNAA=; b=ddbP2ESer1s+4iW1+P8jbyRkDPJI6HWp8uYbItjEImvRjk7JrHqndVCtKhHaDYPdpz b6vpkz+EMyTguUjC4WKHzxewwL5aHYkEwZSZtwIkt/+a8azG/1BB76w6jbdGMICj4tSG MMzxpJTDuCyElpDbu+EdhJDZQ+wj3jgoZFJ0zoAWnv3WEset9Xz3ErUH2DF33cGU3mxi JWveyeqzDyqiZbhLeBts/ZYqtdmjB72TEcmFDkW1DZ9Ss1iM76obWnZ/MvsueNhZRx7L +R8jC6ZxFSGWXQU2sk/H4e3ODe7lbh8OlF0TbQ/400xRCm4Bq4G16ZMmktWr2ZYYNDn4 9qMw== X-Gm-Message-State: AJaThX7KEcAQOy8NxBu6yj5FJ6GAyYN4Tltxw8tRhjQ6gCHAJuiIREy5 ICEvYuaumR+uoyqt4gJ2N8GyS57I X-Google-Smtp-Source: AGs4zMa8ayUlv0KrZ4TRTk9BFljHFraFhGIVkKKwoGTPMUg6mwGHXyJcqcYlGmb7IeanbH8aG734Tw== X-Received: by 10.55.214.91 with SMTP id t88mr35818005qki.274.1511445923152; Thu, 23 Nov 2017 06:05:23 -0800 (PST) Received: from sven-desktop.home.narfation.org (p2003007C6F53F7FA6FAE965552C91071.dip0.t-ipconnect.de. [2003:7c:6f53:f7fa:6fae:9655:52c9:1071]) by smtp.gmail.com with ESMTPSA id o145sm4441997qke.76.2017.11.23.06.05.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:22 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:40 +0100 Message-Id: <20171123140444.17119-7-sven.eckelmann@openmesh.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171123140444.17119-1-sven.eckelmann@openmesh.com> References: <20171123140444.17119-1-sven.eckelmann@openmesh.com> Subject: [B.A.T.M.A.N.] [PATCH 06/10] batctl: Handle nl_cb_alloc errors X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Cc: Sven Eckelmann Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" 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 --- 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;