From patchwork Thu Nov 23 14:04:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17152 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 974D380618; Thu, 23 Nov 2017 15:05:07 +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="j36ZaUSd"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by open-mesh.org (Postfix) with ESMTPS id C3622805ED for ; Thu, 23 Nov 2017 15:05:05 +0100 (CET) Received: by mail-qk0-x241.google.com with SMTP id c123so10701845qkf.7 for ; Thu, 23 Nov 2017 06:05:05 -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=yFx4RCb8xtR1eR4ZduVVHVPN3A2G14Hb9SEOhIASTKY=; b=j36ZaUSdoBtD4sSeKqYp3v1bZmD0AubpGnFm0npIrAqrDvJDnR6Jm3cZjCg9HZAupe eaPcndcG0iMM4WLVLNRdGeBE3q7qyyw3lsi7UXqpFrqOOKO1NaDUEqtXPnAU1sB9YPDB V+fcc3A0Ns3gMqlKh8X1lj6Nb06rXnLvNBWo6q21jqSIVz3lnJ9/7L63AXq1Ztnf62wx Hj2a0BmbTW9SnHEicktJpsR+Y7KCa5tbgyISGX7uj2fD8JsZ2Bpi5kZy7t6DYBvCjgie m3XtNRQQEdH3A9FuKjvvQDLOABDJu88QWIo5dgaIkT2ASDT0K8Hhy0VtsKF9zuBeysep Pggw== 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=yFx4RCb8xtR1eR4ZduVVHVPN3A2G14Hb9SEOhIASTKY=; b=LSqCl+x1Pfyswn7w3lNrpjwnIkzNLYtDDAURKNen2xRj5qo6P7Icp+reZ4RmqGamN9 U2FLr734GaVVZtEPFT4OjAgzVMDsbJGQ4JdW4JPxNhCuJRU4y+ZJ1DGqOc8cEsyWpIbF 3/N9zMBXEEUctjqpBANAm5vEAEqqNtW9dzrC4e020dMbR1ff5/W9OjzCm7Bi788rOK12 Yobo8KRC2GtIFqZk7GQ7/efWUTQHvNqJeU/cf7rRxMKAgvEfeNf2ts73RvNw+v6qgOz6 qNUkIjPSKzonHzpgIak6nxRbdWmXWW3sWCT6jnYQ/lYjiud/iNTSIHmz0YmlY4PeJFsP 3KpA== X-Gm-Message-State: AJaThX7M4H7GOcOv9z37p6SF9PJanRXXDRip+rAfhAeKG7lvVzeqNZsZ DEJwV0+/qXXf0QGcBfb2IQzy6O0m X-Google-Smtp-Source: AGs4zMZozolvVA8gOb3JKk4pklaeHeZzcUuokPA87p+36c5+fYKg2tgNym5BF5madvNCgvCmgT27Rg== X-Received: by 10.55.18.92 with SMTP id c89mr37696789qkh.297.1511445904379; Thu, 23 Nov 2017 06:05:04 -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 g47sm13001075qtc.69.2017.11.23.06.05.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:03 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:35 +0100 Message-Id: <20171123140444.17119-2-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 01/10] batctl: Print dummy value when localtime failed 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" localtime can return NULL when the local time could not be calculated. Accessing this NULL pointer is not allowed. Fixes: 05f27bfcd302 ("add arp packets , change output") Signed-off-by: Sven Eckelmann --- tcpdump.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tcpdump.c b/tcpdump.c index 4ede76b..5eb99cf 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -104,7 +104,11 @@ static int print_time(void) gettimeofday(&tv, NULL); tm = localtime(&tv.tv_sec); - printf("%02d:%02d:%02d.%06ld ", tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); + if (tm) + printf("%02d:%02d:%02d.%06ld ", tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); + else + printf("00:00:00.000000 "); + return 1; } From patchwork Thu Nov 23 14:04:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17153 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 91B8B80674; Thu, 23 Nov 2017 15:05:20 +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="a/ZFbIHK"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by open-mesh.org (Postfix) with ESMTPS id 44DE980639 for ; Thu, 23 Nov 2017 15:05:09 +0100 (CET) Received: by mail-qk0-x241.google.com with SMTP id f63so21093053qke.8 for ; Thu, 23 Nov 2017 06:05:09 -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=xQdc0iUbCaYdNYG4CvcR7IsKX9JmO/AoThxupvwTBnI=; b=a/ZFbIHKZAxgrNJaPfxIhsQTrUbodNO9kUX/cLnu5Fo0s4dmLgM7pRbmdU2cJ0WLO5 xMRR45MYNSfORm3JrtC/fG3JFWXR6X4sYCstl0fkiWMIZX/x8bnNewt6JRJ5DV6isqme BBbeXBVmmtNhyUBEn69WNoaG8+VgTj7M6xZ1yp+Zm77z0oskpIP0oUyrXejSJsPCiz3f jd/VVPiVATfntaqZLdTPxUClqqioPGLYRP1gO5+AwOyPhFsL8GXvYLpi+V2zoFeWrXk3 y+eECPFDruQzMWuNLwOsyn/TC+xrzGEccnd818xCPO4ZrQDShljhmv01IRrVL028Qxn7 EF0Q== 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=xQdc0iUbCaYdNYG4CvcR7IsKX9JmO/AoThxupvwTBnI=; b=mbThEoFFr3aAy9NrRBs5FzyucZQVufQ9Vq+EHnlidWuOZI9jg2sjBaQSAtpUZghI+y 773KAv7rRgUwUNuLKGzyMppl3yBN7xJhR8KZN5D4pt8IwdPFfXn6aZLsR4fkgZYAmxlI 2bZZ8OzZPMksXtTNgit+fxj2fHOTtUe0ajIhxy33edjRZRsNdOe9byIJftcu4ZE8g9hJ 3IfETkc/gm1vVRVOfQFW+e1I8qUed2gRXTtWefZTKvWLhiB0dyPWWrVf8MEMXyRkdEL2 j9sqAcC6tGOpeWsaukNMESK6KinwMRe7c8yTdcO6avBKxJChy5xHCMAsu8oz60Ysj8po BDqA== X-Gm-Message-State: AJaThX6N2UWwujS5VGldIsk3DlGv1AAMcdVJANMI3BTQQe6+rxM7YQsW 8/+IGrTPBpIG2f9zOJ0Ifp8Oyw42 X-Google-Smtp-Source: AGs4zMaco8smOWbd5MZUA8sgBdC/Gefh4+l4u4ZohW0bnEpQi39I7CFibK84HpWVEz7ONx4BnmbEuQ== X-Received: by 10.55.191.135 with SMTP id p129mr17719553qkf.211.1511445908147; Thu, 23 Nov 2017 06:05:08 -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 46sm13171727qtx.65.2017.11.23.06.05.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:07 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:36 +0100 Message-Id: <20171123140444.17119-3-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 02/10] batctl: Handle failure during hash_iterator allocation 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" The iterator functions should not try to start the iteration when the iterator could not be allocated. Signed-off-by: Sven Eckelmann --- hash.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hash.c b/hash.c index f4a7af7..0e4d1e3 100644 --- a/hash.c +++ b/hash.c @@ -120,6 +120,9 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash, if (iter_in == NULL) { iter = debugMalloc(sizeof(struct hash_it_t), 301); + if (!iter) + return NULL; + iter->index = -1; iter->bucket = NULL; iter->prev_bucket = NULL; From patchwork Thu Nov 23 14:04:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17154 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 29B2980676; Thu, 23 Nov 2017 15:05:26 +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="zgIUnz69"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by open-mesh.org (Postfix) with ESMTPS id 099C880478 for ; Thu, 23 Nov 2017 15:05:13 +0100 (CET) Received: by mail-qk0-x241.google.com with SMTP id p19so21091173qke.2 for ; Thu, 23 Nov 2017 06:05:12 -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=AtsGYxTBXyS2RaBNpMD5RIHYVewz9+JGvLI0TyqzOHc=; b=zgIUnz69SOmZe+EYWGiDn1Gm4XXmRP0Z3dCEGPCUsyDDApi+lZKPr0xmPC84bRKA0C L3jqklKgdz8Qizndp0fgHfEI6ebzXvn+tEh5kNHA9J1qlANeNPTXwof74uE1h2L4fHPD 5GUh9q6Rr/U1w90MchnLMihrpzBHKrAwbk9v53/d4MK6zr1ClydUzr3yvFG0Manx7CV8 gCTYmdq1JL9wg7mVLlTRVVbVp+KkoPJmaOUZLfVvywe0Eo4QvS2LtnJm+hyQ3n0kof5E L9MxjifucMHBkR7SFWWomLCr6+5bZhZ5gDrN3Lapn6OKm4pHRMB61SsPnUB0sJe7xPkR OeQA== 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=AtsGYxTBXyS2RaBNpMD5RIHYVewz9+JGvLI0TyqzOHc=; b=DVQtfNYjV28ixsHiPQ9zSXjMk6mwtmfeANzUyqV4jkul8qeYdeBFnRpttooRIakLc1 W2xmUMpG601lugRZwLfikW5joFzBds3sT2DVRABjO3c8e923RkvyP1CpttgYoAjRJnrY mZEHeJam+TbFTbaAg79uRUaw0KYKdpqHO5xGxGrL168a4WHiIwBjTzluBqbf/PGFpkKV Zevqak+gnQcGldCoYYUi8bqRmVleRlmGsW7l0EhkY/WUikz1AtyWpUeTb50qb2YOwPEa iseFs2TmUpkjDwZHXtHRXb5Mu09tQrPfOp6MsHpXXbhvFrFcG53cJBZeQDK2YIMirbj4 albQ== X-Gm-Message-State: AJaThX43CXGxC8Z48hJ/RNEjqXeM/Ns43QfW+uIKCq8AwMEbyluPAuy3 RJ1d6GnYkwFzfryKRRKD1wzlTZt6 X-Google-Smtp-Source: AGs4zMYbBX/gpvy9l3++A2BnI2GgUZM+mBKdSXIhsoKaea8wJhoCO/6TvXL13jCDa5CDdh/GhB679A== X-Received: by 10.55.174.134 with SMTP id x128mr38386064qke.28.1511445911730; Thu, 23 Nov 2017 06:05:11 -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 r22sm12954404qtc.71.2017.11.23.06.05.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:11 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:37 +0100 Message-Id: <20171123140444.17119-4-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 03/10] batctl: Handle allocation error for path_buff 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" Fixes: 5a1af99276b0 ("batctl: adapt batctl to new sysfs interface handling") Fixes: 306fcb4480c9 ("batctl: support for multiple mesh clouds") Fixes: af115c9acf44 ("batctl: support new gateway sysfs API") Fixes: 2c2cb260ad2e ("batctl: list supported and configured routing algorithms") Signed-off-by: Sven Eckelmann --- sys.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys.c b/sys.c index 65b438c..c49b428 100644 --- a/sys.c +++ b/sys.c @@ -153,6 +153,11 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv) } path_buff = malloc(PATH_BUFF_LEN); + if (!path_buff) { + fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n"); + return EXIT_FAILURE; + } + snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface); if (argc != 1) { @@ -255,6 +260,11 @@ int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv) /* prepare the classic path */ path_buff = malloc(PATH_BUFF_LEN); + if (!path_buff) { + fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n"); + return EXIT_FAILURE; + } + snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface); /* if the specified interface is a VLAN then change the path to point @@ -329,6 +339,11 @@ int handle_gw_setting(char *mesh_iface, int argc, char **argv) } path_buff = malloc(PATH_BUFF_LEN); + if (!path_buff) { + fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n"); + return EXIT_FAILURE; + } + snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface); if (argc == 1) { From patchwork Thu Nov 23 14:04:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17155 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 1ABE4806B6; Thu, 23 Nov 2017 15:05:34 +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="crlUggAG"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by open-mesh.org (Postfix) with ESMTPS id 8A4068066D for ; Thu, 23 Nov 2017 15:05:20 +0100 (CET) Received: by mail-qk0-x241.google.com with SMTP id w125so21101227qkb.6 for ; Thu, 23 Nov 2017 06:05:20 -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=UwtIz3GVOI5/qazVEzjRp6q3PKDJjZmfZFmfxzCkIOo=; b=crlUggAGUdcBbE7yn+GfwgYUGU/45j1iVW41oj2CjnIsE0DhynR/cRzc+JrwFD9li8 hZVcjqxNe3ys/qB6F7Uz3SB1EDzGKB4Ekb16ebs4lPKu6vUaaTAJDS6NprGf37ZKgPeD nywuS+MqDmaSZ05caVniJe2LJcrcTnGU0rePWN6DPlnNZUBfPumj2k8Zse16IZUgSxvm UMnm01Bk4FLuMhVPfkf2kWrUm8Vniys9ZnOVQJLK9qogV2i++Zc5lAKtpXEhVvcg04DJ ltiFLa+dAk4OBcaB1VDcts3NoQuZcGOTwhc5NB02VtFRMfWOwCF4dHWAKN2pa24nvkuz WthQ== 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=UwtIz3GVOI5/qazVEzjRp6q3PKDJjZmfZFmfxzCkIOo=; b=EfxQD8XX0qWvO/yxo36w/6V66S7lvzmEXS4A4wyBO/fM4YLqx3Nj1rVildd94UEOmu xdzwOMsRfRtARhxgXJIljGK5KOiViyeVLbteLQQidgaCjEY9DgVTWZtG/JVK9t5rdvHe RaMirCj4ocBe/LYHqRQcOJXibeeN3ucDxCYLby88YTQnIETzyu9uphR3HxNeDiu3Xrva xWJy0zoD/PzNVWtnDHssR+rFG5YaZdzanwCZXnTj1domRTZYWy7t+o1qtVb5wK+PHPoo /jNtS0mZP4vupMP0NAS63pRlGgX4Yf2QoqnKGTj5LauTpQZXAumy0g968Ud4ejWxtg4y bpcw== X-Gm-Message-State: AJaThX5EO4zpKlqBti86z4S14SbX2LB8zPmJDAqC9OppuGgeXYDeXVkp /YUVGQAqfO5Oa6CeSUsp6MIC6QmO X-Google-Smtp-Source: AGs4zMbznacUtT9AO5zIuUvh7hL5Q/M/zytvitMJA/INjvbH3+A48TB51gC6CdZAFy0j7tWXZuQnDQ== X-Received: by 10.55.145.197 with SMTP id t188mr23684851qkd.267.1511445915587; Thu, 23 Nov 2017 06:05:15 -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 y66sm6895232qkd.46.2017.11.23.06.05.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:15 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:38 +0100 Message-Id: <20171123140444.17119-5-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 04/10] batctl: Handle nlmsg_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" nlmsg_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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/netlink.c b/netlink.c index 7fb1ee1..e3d7892 100644 --- a/netlink.c +++ b/netlink.c @@ -302,6 +302,11 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header) return NULL; msg = nlmsg_alloc(); + if (!msg) { + nl_socket_free(sock); + return NULL; + } + genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0, BATADV_CMD_GET_MESH_INFO, 1); @@ -399,6 +404,11 @@ int netlink_print_routing_algos(void) return -EOPNOTSUPP; msg = nlmsg_alloc(); + if (!msg) { + last_err = -ENOMEM; + goto err_free_sock; + } + genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_DUMP, BATADV_CMD_GET_ROUTING_ALGOS, 1); @@ -415,6 +425,8 @@ int netlink_print_routing_algos(void) nl_cb_err(cb, NL_CB_CUSTOM, print_error, NULL); nl_recvmsgs(sock, cb); + +err_free_sock: nl_socket_free(sock); if (!last_err) @@ -1131,6 +1143,9 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface, header); msg = nlmsg_alloc(); + if (!msg) + continue; + genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_DUMP, nl_cmd, 1); From patchwork Thu Nov 23 14:04:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17156 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 013DF80736; Thu, 23 Nov 2017 15:05:46 +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="LyHZJ+D0"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::242; helo=mail-qt0-x242.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) by open-mesh.org (Postfix) with ESMTPS id 13E1B8060C for ; Thu, 23 Nov 2017 15:05:22 +0100 (CET) Received: by mail-qt0-x242.google.com with SMTP id r58so28092846qtc.0 for ; Thu, 23 Nov 2017 06:05:22 -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=W7uISMSB4oZxgyIxqzAhpNHH4aC7d1v/LhlY7Far7is=; b=LyHZJ+D0f4h89EtXuDW/wG0nR8XCXTTsvDofHpHUcuAI5SSk8UZsf4aZTjTsdwGdBs CnPx2sTJzoauFVC8+CtQny2md95ELNm5Gowp+8v+nRvi6NhlwsxT5MHDJx7lBN6lI7YH fE7tKKY3KeRUkJBiT4H3OLcOsC0+9fiXI8lArihJh3L8WLGkrzGGLV1rxGolviCq/rjj juq5Nzet5cTMgaWG3Zu5la91CGmpCw1SjHwZgyXIvcD8LTQNKE5/Id98DdN1RqG+28I1 it1MFME9xIDgZmQbe+ss+vLMTNhIULGOh2DJmldCCkPnByUu6CCiqGOe4iMg+RgrKDDV 6mVg== 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=W7uISMSB4oZxgyIxqzAhpNHH4aC7d1v/LhlY7Far7is=; b=pdrg9yAYyJ3O5WH22Um2N0aFmMsflENQmCXEKvatk1MPF8Voeo772ajCo5MJo9fqyH LxkhgPj1TolZAr9zim/DQVcDzT4qBsIIMztvFu7OmNHh3UvIZY6t/9YBOYTLDV2g43+E Sat4SYwA8N9ic0PXdjmmCShELMGegaq29Y1rM25+dPtxM4ahMlnfb3ldlMxtlpgCOBGu 2Ze8V00Hc1m7VpG/NMiOiTc7T4Zwadu/jImUT8Nw/2U4OCbu5kjDVzH1cn4DdVq1HUwl tRoJrPVNbOgLpgOhTUbneM8+sLjtX5bwEHEuEwkjl99FYxWPMuxVWIzqOT4l/uAKWskc gESA== X-Gm-Message-State: AJaThX6ZLiffLriouKJazH5CbyLLehF5BzPqN0XY0XTDY7soUuTsDIPE YUHfE0m26/oM++/zCS1jhhwzbd7V X-Google-Smtp-Source: AGs4zManCkqpV/do5pwdOsEDfNRw3gG4UerMKjfTzbmYUB4TUC/sCOhVTwh06oiUC7rHm2buukjQUg== X-Received: by 10.237.35.246 with SMTP id k51mr38949877qtc.163.1511445919442; Thu, 23 Nov 2017 06:05:19 -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 y58sm13104568qtb.9.2017.11.23.06.05.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:19 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:39 +0100 Message-Id: <20171123140444.17119-6-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 05/10] batctl: Handle nl_socket_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_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 --- netlink.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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); 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; From patchwork Thu Nov 23 14:04:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17158 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 534C180873; Thu, 23 Nov 2017 15:06:04 +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="zUZBD2oq"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::241; helo=mail-qk0-x241.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) by open-mesh.org (Postfix) with ESMTPS id E517D806A5 for ; Thu, 23 Nov 2017 15:05:29 +0100 (CET) Received: by mail-qk0-x241.google.com with SMTP id c123so10703179qkf.7 for ; Thu, 23 Nov 2017 06:05:29 -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=+rXBBfY5XaqOl9+xkE2OMgybYanEq/VAp9MLFR1F/5A=; b=zUZBD2oqJLZuBy3clAZWZelddzTBaS+ySfZhocheoqU9qk6HnVfLFWosq2J8YEIRkq 26FLwL86ziB8F9JWYlU1LrwaRN54e4IoUmNruuyUpM7JQqfaodKKO2SXA2AfINZos3sl dAW/itMGe60mgcMr4uYZ24/d6xNo/IG0bdw8mqIqdQMjGzfzNOVVuzIFp0QCKF4z39oo rxFJVNm9Gx4jWI3eHcA7Ub50avGqLj0KzAJlZjiO762YhjCiqv7kEywnQ3PC8ZsXKnqA 6GXtWUBJQv/jkDpWnM0BRkDjMCKws41nK4A4fa9JpSck/b3h3IZQekY0vtXXrM+m3uRu TSrw== 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=+rXBBfY5XaqOl9+xkE2OMgybYanEq/VAp9MLFR1F/5A=; b=IJ9us2+UKDfhuOaPQJwGtyjKoONZA00dCEOq0MSUMCPZDRmL852NHKt4gS7D32MrZ0 1psYEFaUO90Xzx5HEiCWZ6DkBTpllQanq+RE/iVEQzTofvgF92XAHsY8sE7aFCgVtSgJ uAFQ1ZbgJfaJfDtin/jtw4eGvLLRo1h3USb4S6ma5YEGbqYsi6dJEdxHhrgAxKCJAumk ivCeQeHWhRfQbeNnZ3F9olKHx8EKaAMoC3lvxcDZZH8mjNybQ+6KxV6s15tZMS/+1FXF 7Ebwip7RmjG5rOA6fel7hJQ/89c0fa0kxN7orCAQFgpv40jW70MCcFahlKucBIgBD/51 xVrA== X-Gm-Message-State: AJaThX4h5g5HjaJTvSunyeSxIyjhcNL6DGywycFAWN/4yhRD8XZLj+HB upGCXHC7RfflPsYqIO2mWxWmA/YB X-Google-Smtp-Source: AGs4zMZcvWA/5yQXVZmVkKTILJhV1yuhM+0UXlNW4oJjNJPBTEi7JdtNsVjeae1k8sEFHslwb+9X8g== X-Received: by 10.55.39.84 with SMTP id n81mr18421822qkn.278.1511445926892; Thu, 23 Nov 2017 06:05:26 -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 2sm13325314qto.28.2017.11.23.06.05.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:26 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:41 +0100 Message-Id: <20171123140444.17119-8-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 07/10] batctl: Free nl_sock on genl_ctrl_resolve error 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" genl_ctrl_resolve may return NULL on errors. The code must then free the socket which was used to start the genl_ctrl_resolve and stop the function with an error code. Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs") Signed-off-by: Sven Eckelmann --- netlink.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/netlink.c b/netlink.c index b95063a..de81d08 100644 --- a/netlink.c +++ b/netlink.c @@ -301,8 +301,10 @@ static char *netlink_get_info(int ifindex, uint8_t nl_cmd, const char *header) genl_connect(sock); family = genl_ctrl_resolve(sock, BATADV_NL_NAME); - if (family < 0) + if (family < 0) { + nl_socket_free(sock); return NULL; + } msg = nlmsg_alloc(); if (!msg) { @@ -410,8 +412,10 @@ int netlink_print_routing_algos(void) genl_connect(sock); family = genl_ctrl_resolve(sock, BATADV_NL_NAME); - if (family < 0) - return -EOPNOTSUPP; + if (family < 0) { + last_err = -EOPNOTSUPP; + goto err_free_sock; + } msg = nlmsg_alloc(); if (!msg) { @@ -1125,8 +1129,10 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface, genl_connect(sock); family = genl_ctrl_resolve(sock, BATADV_NL_NAME); - if (family < 0) - return -EOPNOTSUPP; + if (family < 0) { + last_err = -EOPNOTSUPP; + goto err_free_sock; + } ifindex = if_nametoindex(mesh_iface); if (!ifindex) { From patchwork Thu Nov 23 14:04:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17159 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 77CB3808DD; Thu, 23 Nov 2017 15:06:12 +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="wFBWoKg7"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::242; helo=mail-qt0-x242.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) by open-mesh.org (Postfix) with ESMTPS id 25CA9805EC for ; Thu, 23 Nov 2017 15:05:33 +0100 (CET) Received: by mail-qt0-x242.google.com with SMTP id a19so28041307qtb.3 for ; Thu, 23 Nov 2017 06:05:33 -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=G0mj60513jWw3YnjomHbC9W1Po/FTJHI6ltu500lTrw=; b=wFBWoKg7ydJEYwG69FLbDBCmRCbWPDjkaTv8ULqt/kNVVmndcVUR/gVJH7A2Jb+t4S CnNSwo8PArdsvXzs350vhm/3+uFGWh+IrFzMIkxwKQa2MEoQ/LKsscfeP3pW6Zlshclf MDGS9J3QJJYHQgehjUuF8/5ehTMCUAo9g5zUb1WAqSOEFrtnozAAnEgu9KRGVaMC+CV+ kFf1haXYiiB7GPEJInAxiCBoy9jcIUpRiL1wMkhSbeoB0WgTVpQ+Nup1dTngleUoth/M nJgDZwOXDpEj9q7wguI+OFXOMlY9Cs6aha8jHgbWXxfCbC3doaKSVcVekHOgvmUFVvn+ nHew== 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=G0mj60513jWw3YnjomHbC9W1Po/FTJHI6ltu500lTrw=; b=Cw5P2OxRsrWZvPj8BBEHZ8nIaCnty3JmE2myaXvLJG7qPcyH8sgpm/1Bc9/DZ1huQG mamH1VscamfynjlW7h4Pv8gdswUWRRbdXlkwdV5EGj5gGplAWxA25M3ITJk71J0Wy0Uz PxXH9jhIUZd5NyV+ijVVz99chKIeF3cFoD2enEcNRswnzQc93Q8zijM+Bj7e6L/WBKcK +d2wU/qralZFARPgNutxZqNyovWOMnar+j8FsKIUFFfrthQddTEVh/U6dfUp2zICf9Sk FwjKwOvAWVBl7ilSjauVOPPognwmvRZi6+nzvaca2RFx1A0pi4ArP1ghGAGiOOp7JM6O RBLA== X-Gm-Message-State: AJaThX4UVregCDffVhH6ytCtf6hyWyvQTRemJhL9g8Ck5qaHqDcO54ws MxvNzUp9zCbzHLpPOOWGhkPxGBg2 X-Google-Smtp-Source: AGs4zMZ0AczCXf3fftVyU3zI/kWD+3qF1TbYp4fZqcXtrasb9t2myuNa/OM0xDHpURbBk/P6CvJCsg== X-Received: by 10.200.4.154 with SMTP id s26mr40511629qtg.156.1511445930645; Thu, 23 Nov 2017 06:05:30 -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 y9sm8473309qti.63.2017.11.23.06.05.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:30 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:42 +0100 Message-Id: <20171123140444.17119-9-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 08/10] batctl: Free nl_sock when if_nametoindex failed 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" The if_nametoindex can return an error. The code must then free the previously allocated nl_sock and stop the function with an error code. Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs") Signed-off-by: Sven Eckelmann --- netlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netlink.c b/netlink.c index de81d08..7b97809 100644 --- a/netlink.c +++ b/netlink.c @@ -1137,7 +1137,8 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface, ifindex = if_nametoindex(mesh_iface); if (!ifindex) { fprintf(stderr, "Interface %s is unknown\n", mesh_iface); - return -ENODEV; + last_err = -ENODEV; + goto err_free_sock; } if (orig_iface) { @@ -1145,7 +1146,8 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface, if (!hardifindex) { fprintf(stderr, "Interface %s is unknown\n", orig_iface); - return -ENODEV; + last_err = -ENODEV; + goto err_free_sock; } } From patchwork Thu Nov 23 14:04:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17160 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 AC4438092A; Thu, 23 Nov 2017 15:06:20 +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="TqG6dGIl"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c09::243; helo=mail-qk0-x243.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) by open-mesh.org (Postfix) with ESMTPS id 6AB488070B for ; Thu, 23 Nov 2017 15:05:36 +0100 (CET) Received: by mail-qk0-x243.google.com with SMTP id 136so21089967qkd.4 for ; Thu, 23 Nov 2017 06:05:36 -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=8wxcJ1aBnKIjy3vC8m5YtcMUZdghguHftLGmgimtD5E=; b=TqG6dGIly+EGClwNkSAqfc4sYcfH/MzKG5chpsKsWN3EJU33Iqmei/1unV5CKJMBxC bpY0F8RS0nxDk0bP3OBDU1EJ/UBdgGW0Bt0jXSeyl2QC6YPS5mk7vWHRXviEAhnS2Pfv RWuLx794FtNmNBf31D+qCvh1Lscwo4BnBMZAAmR1/QURkGKBPvpaFyVKJRQeiTKW3yWb XOVBzwXwMPZTLndWkil0Pvqp4y/UJ9mV5LR2Ud6FkCB5AzY7C7kVqlbxPGTMVmTvXlc2 BuH/aPjl7zHPuPromUUDasFVjY1l1tpoVPUDax9HqMhkoeZIuD+k301vI1UjtG5JbjFR KTjg== 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=8wxcJ1aBnKIjy3vC8m5YtcMUZdghguHftLGmgimtD5E=; b=QxOfzjjzCxHkMoJwPYG4Im2JNSQVpdnp7evfjdV/hNdIRa7TFZb0U5LjX+IZPrrM6g P7stJWtlSCi2Ub7hZwpaZXJIrSCHglq5Lhz/d5136iitu1ERZRhRV0zG+twx8Os8b+/w USXNsFwa3LZWFH8EgaOGf3glc2zx3Hrm2oK0YIQOzZqi8T0argso2F8fZzcKHFqn45Ih MDC4AF7kmc7gogWKsBwf7ZpwEEjhX6zVllFgK44BOtka0ZvI6xdtocLkU3LF2yAIWSwT 9kafl5LPRILOjy4u7lbzZsKz+yAMPwnecjXHkFPzB7ye3ZZYHAMYQAnU+D7pewta/n8y lrgA== X-Gm-Message-State: AJaThX53iWilGI8jgAMfl2kUB2z3o6k0dnM9/Iqsb+guttPedn1bRjnK InTsrWyAGef8zy4H36NFyskucVOq X-Google-Smtp-Source: AGs4zMaQsKbCgMmbMNN6Gh9eatOT1TXMiizvnK7k/oOlU6TQh7NwZY3UCGhfZXFyryT2zzYd05Sw0w== X-Received: by 10.233.244.72 with SMTP id z8mr39080120qkl.107.1511445934450; Thu, 23 Nov 2017 06:05:34 -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 f5sm13176785qte.87.2017.11.23.06.05.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:34 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:43 +0100 Message-Id: <20171123140444.17119-10-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 09/10] batctl: tcpdump: Fix types for for TT v1 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" The num_entry and num_vlan variables are accessed (printed) as u16 variables and not like integers. They should therefore also be stored like that. Signed-off-by: Sven Eckelmann --- tcpdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tcpdump.c b/tcpdump.c index 5eb99cf..a1b057b 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -158,7 +158,8 @@ static void batctl_tvlv_parse_tt_v1(void *buff, ssize_t buff_len) { struct batadv_tvlv_tt_data *tvlv = buff; struct batadv_tvlv_tt_vlan_data *vlan; - int i, num_vlan, num_entry; + int i; + unsigned short num_vlan, num_entry; const char *type; size_t vlan_len; From patchwork Thu Nov 23 14:04:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17161 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 EFFEB80961; Thu, 23 Nov 2017 15:06:28 +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="saQl9SiS"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::243; helo=mail-qt0-x243.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) by open-mesh.org (Postfix) with ESMTPS id 00E388065C for ; Thu, 23 Nov 2017 15:05:39 +0100 (CET) Received: by mail-qt0-x243.google.com with SMTP id r58so28093972qtc.0 for ; Thu, 23 Nov 2017 06:05:39 -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=OqY7lIAFQeH4Pc/H9yP0kreTqpver3+LzjQ9csOYEjw=; b=saQl9SiSHZCJ5Ts335y+fkXwNf6k2wRZGzfSSHFQz9JnZwxl1a4f9H+M6hqaQ76A2B W22HR+iMafArbpEKrIfQ5tJEwfGZ9HnA/TgSPuf46dBvlKksMKAC4ewj0//uPoNPXE2X xKmNFDChU89+K4oc67xvHnVD//hWFWrEC2N7hdkg2vrfEP/agTk/qTVCy1xgQSbhvdFI 33EvUD52alLqjYnlVtprEZ4a3LnRy2X5HZlu2ZfsijDGWq8EyaR9uFVbjncW4FnnluRI oY5HrUFQ7ljqGgZn75tPSZoUi6CinglQenJLnzKdxBVvURJ6tYq5HWAdwvHKdt8eb7CO HhTw== 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=OqY7lIAFQeH4Pc/H9yP0kreTqpver3+LzjQ9csOYEjw=; b=gcjGEpLLkWv6NjoAF7V0lLAtRJhDiLgPWokvQFmDwXP+FioWvz7a6fpggDoqgUc8oK xJQIHA5l3WaRaTeh+ZSwTARju6PiqmcAAipX0/WBSCpOBq9lFm/dzEn9XWVPG6usff00 vcE2ISyBs80HXWx0s8YMzNwPfgo6s9XW0B4HRAzz5q0dUnGVZ1XVwrYCB8+diOkrsqBF 6DA+FNmJN8gLD8S/+O57TFPLy0sWS8/WOXxx7wnVLJfjG8qrijP0GEG4k+UNJpug35z3 Le1Ms/YSrcdMnbxTGcP/baAjUBH6qhhIehxtmvR0T2P4Uh8Zv0RnfvUAZ/tLF7Vxp1E6 hhDg== X-Gm-Message-State: AJaThX757dZeLPIdjBpIFX0XvnC6VqhTJiq2zbO7Pwr4iYl0HDuZPlf0 8xnP14ARduVomRKyDbNVnbPE4pXI X-Google-Smtp-Source: AGs4zMb9LgdvlEYHaPzPdzp5c4+2vf/Jrz/hVCdpFzL7o+T0MW1S2PcLidVS99dGLeizWdol5ifyOg== X-Received: by 10.237.34.193 with SMTP id q1mr37451375qtc.78.1511445938420; Thu, 23 Nov 2017 06:05:38 -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 j7sm12759037qth.25.2017.11.23.06.05.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:37 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:44 +0100 Message-Id: <20171123140444.17119-11-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 10/10] batctl: Simplify concatenation of pathnames 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" The combination of strncpy and strncat is hard to read and it is rather easy to introduce some kind of problems when using that. The usage of snprintf simplifies it slightly. Signed-off-by: Sven Eckelmann --- bat-hosts.c | 4 +--- functions.c | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bat-hosts.c b/bat-hosts.c index b530243..54b0a18 100644 --- a/bat-hosts.c +++ b/bat-hosts.c @@ -194,9 +194,7 @@ void bat_hosts_init(int read_opt) if (!homedir) continue; - strncpy(confdir, homedir, CONF_DIR_LEN); - confdir[CONF_DIR_LEN - 1] = '\0'; - strncat(confdir, &bat_hosts_path[i][1], CONF_DIR_LEN - strlen(confdir) - 1); + snprintf(confdir, CONF_DIR_LEN, "%s%s", homedir, &bat_hosts_path[i][1]); } else { strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN); confdir[CONF_DIR_LEN - 1] = '\0'; diff --git a/functions.c b/functions.c index 868e0ae..8bcf52d 100644 --- a/functions.c +++ b/functions.c @@ -208,9 +208,7 @@ int read_file(const char *dir, const char *fname, int read_opt, if (read_opt & USE_BAT_HOSTS) bat_hosts_init(read_opt); - strncpy(full_path, dir, sizeof(full_path)); - full_path[sizeof(full_path) - 1] = '\0'; - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1); + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname); open: line = 0; @@ -349,9 +347,7 @@ int write_file(const char *dir, const char *fname, const char *arg1, char full_path[500]; ssize_t write_len; - strncpy(full_path, dir, sizeof(full_path)); - full_path[sizeof(full_path) - 1] = '\0'; - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1); + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname); fd = open(full_path, O_WRONLY);