batctl: Merge bugfixes from v2017.4
authorSven Eckelmann <sven@narfation.org>
Tue, 26 Dec 2017 11:05:17 +0000 (12:05 +0100)
committerSven Eckelmann <sven@narfation.org>
Tue, 26 Dec 2017 12:09:35 +0000 (13:09 +0100)
* Handle allocation error in vlan_get_link_parse
* Simplify concatenation of pathnames
* tcpdump: Fix types for for TT v1
* Free nl_sock when if_nametoindex failed
* Free nl_sock on genl_ctrl_resolve error
* Handle nl_cb_alloc errors
* Handle nl_socket_alloc errors
* Handle nlmsg_alloc errors
* Handle allocation error for path_buff
* Handle failure during hash_iterator allocation
* Print dummy value when localtime failed
* suppress implicit-fallthrough compiler warning
* change PATH_BUFF_LEN to maximal possible value

Signed-off-by: Sven Eckelmann <sven@narfation.org>
14 files changed:
batctl/Makefile
batctl/patches/0001-batctl-change-PATH_BUFF_LEN-to-maximal-possible-valu.patch [new file with mode: 0644]
batctl/patches/0002-batctl-suppress-implicit-fallthrough-compiler-warnin.patch [new file with mode: 0644]
batctl/patches/0003-batctl-Print-dummy-value-when-localtime-failed.patch [new file with mode: 0644]
batctl/patches/0004-batctl-Handle-failure-during-hash_iterator-allocatio.patch [new file with mode: 0644]
batctl/patches/0005-batctl-Handle-allocation-error-for-path_buff.patch [new file with mode: 0644]
batctl/patches/0006-batctl-Handle-nlmsg_alloc-errors.patch [new file with mode: 0644]
batctl/patches/0007-batctl-Handle-nl_socket_alloc-errors.patch [new file with mode: 0644]
batctl/patches/0008-batctl-Handle-nl_cb_alloc-errors.patch [new file with mode: 0644]
batctl/patches/0009-batctl-Free-nl_sock-on-genl_ctrl_resolve-error.patch [new file with mode: 0644]
batctl/patches/0010-batctl-Free-nl_sock-when-if_nametoindex-failed.patch [new file with mode: 0644]
batctl/patches/0011-batctl-tcpdump-Fix-types-for-for-TT-v1.patch [new file with mode: 0644]
batctl/patches/0012-batctl-Simplify-concatenation-of-pathnames.patch [new file with mode: 0644]
batctl/patches/0013-batctl-Handle-allocation-error-in-vlan_get_link_pars.patch [new file with mode: 0644]

index 60c3dd9801a557012eb2fd71fa11c77b435b138a..75c41175239d1440fdb33282704fe97414241fe8 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=batctl
 
 PKG_VERSION:=2016.5
-PKG_RELEASE:=0
+PKG_RELEASE:=1
 PKG_MD5SUM:=7b33fb47c7fa5b317e9a152a286999fc
 PKG_HASH:=07edeb1d87a548285be8c499542790a158fc8d94ef7ebb295f27ebf710024ae9
 
diff --git a/batctl/patches/0001-batctl-change-PATH_BUFF_LEN-to-maximal-possible-valu.patch b/batctl/patches/0001-batctl-change-PATH_BUFF_LEN-to-maximal-possible-valu.patch
new file mode 100644 (file)
index 0000000..931d14a
--- /dev/null
@@ -0,0 +1,47 @@
+From: Philipp Psurek <philipp.psurek@gmail.com>
+Date: Tue, 13 Jun 2017 10:25:59 +0200
+Subject: [PATCH] batctl: change PATH_BUFF_LEN to maximal possible value
+
+The output of
+
+snprintf(path_buff, PATH_BUFF_LEN, SYS_ROUTING_ALGO_FMT, iface_dir->d_name)
+
+in sys.c can be between 34 and 289 bytes and should not write into a
+destination of size 200.
+
+Signed-off-by: Philipp Psurek <philipp.psurek@gmail.com>
+[sw: use higher limits to be future-proof]
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/620226bf8cff30e6dd966c8fe922b2d4cddf843b
+---
+ functions.c | 2 +-
+ functions.h | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/functions.c b/functions.c
+index abd588209337dcfa04be9aadbf4ba39bb46771bb..676012bb56f9f8aa757b4805e27d904181ee2d27 100644
+--- a/functions.c
++++ b/functions.c
+@@ -59,7 +59,7 @@
+ #include "debugfs.h"
+ #include "netlink.h"
+-#define PATH_BUFF_LEN 200
++#define PATH_BUFF_LEN 400
+ static struct timespec start_time;
+ static char *host_name;
+diff --git a/functions.h b/functions.h
+index 95cd6cf32b0c97cc36f7a81a7d8b126a0bbc389b..99e9085b4f392452d0e0b711dac334559408c1fb 100644
+--- a/functions.h
++++ b/functions.h
+@@ -31,7 +31,7 @@
+ #define ETH_STR_LEN 17
+ #define BATMAN_ADV_TAG "batman-adv:"
+-#define PATH_BUFF_LEN 200
++#define PATH_BUFF_LEN 400
+ /* return time delta from start to end in milliseconds */
+ void start_timer(void);
diff --git a/batctl/patches/0002-batctl-suppress-implicit-fallthrough-compiler-warnin.patch b/batctl/patches/0002-batctl-suppress-implicit-fallthrough-compiler-warnin.patch
new file mode 100644 (file)
index 0000000..0c3f7f9
--- /dev/null
@@ -0,0 +1,43 @@
+From: Philipp Psurek <philipp.psurek@gmail.com>
+Date: Tue, 13 Jun 2017 13:08:24 +0200
+Subject: [PATCH] batctl: suppress implicit-fallthrough compiler warning
+
+GCC 7.1.0 complains about an intended fallthrough.
+“__attribute__ ((fallthrough))” in this part of code would suppress this
+warning. Because older GCC compiler don’t understand this statement attribute
+and because there is already a comment in the source containing
+“falls?[ \t-]*thr(ough|u)” we can suppress the warning with the
+“-Wimplicit-fallthrough=2” warning option. Unintended fallthroughs without a
+comment would trigger this warning again.
+
+To avoid compiler recognition in the Makefile a simply change of the comment
+is sufficient to suppress the warning. For some reason only stand alone
+comments mentioned in [1] are recognized so the comment has to be split up into
+two parts.
+
+[1] https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#index-Wimplicit-fallthrough_003d
+
+Signed-off-by: Philipp Psurek <philipp.psurek@gmail.com>
+[sw: Put the second comment part into a new line to avoid clutter]
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/50ee3c45feeda6d8c04ee127097badf99f78a26e
+---
+ tp_meter.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/tp_meter.c b/tp_meter.c
+index f95b8391ff3426200697034f1087274ca9e5a9dd..ec0dc4802c638471ff3c38bd344e31c208b634a5 100644
+--- a/tp_meter.c
++++ b/tp_meter.c
+@@ -498,8 +498,9 @@ int tp_meter(char *mesh_iface, int argc, char **argv)
+               break;
+       case BATADV_TP_REASON_CANCEL:
+               printf("CANCEL received: test aborted\n");
+-              /* fall through and print the partial result */
++              /* fall through */
+       case BATADV_TP_REASON_COMPLETE:
++              /* print the partial result */
+               if (result.test_time > 0) {
+                       throughput = result.total_bytes * 1000;
+                       throughput /= result.test_time;
diff --git a/batctl/patches/0003-batctl-Print-dummy-value-when-localtime-failed.patch b/batctl/patches/0003-batctl-Print-dummy-value-when-localtime-failed.patch
new file mode 100644 (file)
index 0000000..a29b740
--- /dev/null
@@ -0,0 +1,33 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:35 +0100
+Subject: [PATCH] batctl: Print dummy value when localtime failed
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/09dd2dc0b4945c83bd07ad4bce64062239d901fb
+---
+ tcpdump.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/tcpdump.c b/tcpdump.c
+index 2125b66d0871c4a127425bfad0135a9f565cfb78..db9c46afecf3de94dbd4d9292df1fe0812fb8bfc 100644
+--- a/tcpdump.c
++++ b/tcpdump.c
+@@ -103,7 +103,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;
+ }
diff --git a/batctl/patches/0004-batctl-Handle-failure-during-hash_iterator-allocatio.patch b/batctl/patches/0004-batctl-Handle-failure-during-hash_iterator-allocatio.patch
new file mode 100644 (file)
index 0000000..1182cab
--- /dev/null
@@ -0,0 +1,29 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:36 +0100
+Subject: [PATCH] batctl: Handle failure during hash_iterator allocation
+
+The iterator functions should not try to start the iteration when the
+iterator could not be allocated.
+
+Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/aa316bf6d1b2cf0ab7189ed8620c17f5018d4d37
+---
+ hash.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/hash.c b/hash.c
+index 08d47b5b8f812d718f9463c548d73fbffb49b1b3..c6f735c64b573928441b41936646d195bc0da4bb 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;
diff --git a/batctl/patches/0005-batctl-Handle-allocation-error-for-path_buff.patch b/batctl/patches/0005-batctl-Handle-allocation-error-for-path_buff.patch
new file mode 100644 (file)
index 0000000..f58427b
--- /dev/null
@@ -0,0 +1,56 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:37 +0100
+Subject: [PATCH] batctl: Handle allocation error for path_buff
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/3b52283a5f60d1c6ec11628d031e72f0a28a720f
+---
+ sys.c | 15 +++++++++++++++
+ 1 file changed, 15 insertions(+)
+
+diff --git a/sys.c b/sys.c
+index b52434072b34b949c73de8346f8c2dce615423a4..3047b5f6eebf26290f2d8c4840d52bb1bddc3e3f 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) {
+@@ -253,6 +258,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
+@@ -325,6 +335,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) {
diff --git a/batctl/patches/0006-batctl-Handle-nlmsg_alloc-errors.patch b/batctl/patches/0006-batctl-Handle-nlmsg_alloc-errors.patch
new file mode 100644 (file)
index 0000000..ec43338
--- /dev/null
@@ -0,0 +1,63 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:38 +0100
+Subject: [PATCH] batctl: Handle nlmsg_alloc errors
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/27e9937635ffbfe33f7f3297aff911718b8deb56
+---
+ netlink.c | 15 +++++++++++++++
+ 1 file changed, 15 insertions(+)
+
+diff --git a/netlink.c b/netlink.c
+index 5f4325b0bb6b4a41860a75bd0851e446c5af9a88..64afeedac46bf3eab14a1d89d7db4491fbef8d81 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);
diff --git a/batctl/patches/0007-batctl-Handle-nl_socket_alloc-errors.patch b/batctl/patches/0007-batctl-Handle-nl_socket_alloc-errors.patch
new file mode 100644 (file)
index 0000000..0d78f7f
--- /dev/null
@@ -0,0 +1,50 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:39 +0100
+Subject: [PATCH] batctl: Handle nl_socket_alloc errors
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/bc6cd37e0d3ce08e3b89e3123ffa87dc55f24c09
+---
+ netlink.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/netlink.c b/netlink.c
+index 64afeedac46bf3eab14a1d89d7db4491fbef8d81..107ca52a4866e25b7b04428d770a885ca4e826d2 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);
diff --git a/batctl/patches/0008-batctl-Handle-nl_cb_alloc-errors.patch b/batctl/patches/0008-batctl-Handle-nl_cb_alloc-errors.patch
new file mode 100644 (file)
index 0000000..8998a77
--- /dev/null
@@ -0,0 +1,72 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:40 +0100
+Subject: [PATCH] batctl: Handle nl_cb_alloc errors
+
+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>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/0a14f8800dac67d706827e9be7745e2319f5412c
+---
+ netlink.c | 17 ++++++++++++++++-
+ 1 file changed, 16 insertions(+), 1 deletion(-)
+
+diff --git a/netlink.c b/netlink.c
+index 107ca52a4866e25b7b04428d770a885ca4e826d2..3eb66c9de30c21722bb1e348b055838ea14d18cf 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;
diff --git a/batctl/patches/0009-batctl-Free-nl_sock-on-genl_ctrl_resolve-error.patch b/batctl/patches/0009-batctl-Free-nl_sock-on-genl_ctrl_resolve-error.patch
new file mode 100644 (file)
index 0000000..047d520
--- /dev/null
@@ -0,0 +1,59 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:41 +0100
+Subject: [PATCH] batctl: Free nl_sock on genl_ctrl_resolve error
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/cdac2f843c616caaa2a0d3847aeec84c200c62d6
+---
+ netlink.c | 16 +++++++++++-----
+ 1 file changed, 11 insertions(+), 5 deletions(-)
+
+diff --git a/netlink.c b/netlink.c
+index 3eb66c9de30c21722bb1e348b055838ea14d18cf..ee58ce8bf16e224374940dddaff61f7b3c5aa4bb 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) {
diff --git a/batctl/patches/0010-batctl-Free-nl_sock-when-if_nametoindex-failed.patch b/batctl/patches/0010-batctl-Free-nl_sock-when-if_nametoindex-failed.patch
new file mode 100644 (file)
index 0000000..206f558
--- /dev/null
@@ -0,0 +1,40 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:42 +0100
+Subject: [PATCH] batctl: Free nl_sock when if_nametoindex failed
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/4361841bf76ecd27dcfca6edc30c63b05854d415
+---
+ netlink.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/netlink.c b/netlink.c
+index ee58ce8bf16e224374940dddaff61f7b3c5aa4bb..88a5c95c67989a812231aec7352eecfc4e38c70d 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;
+               }
+       }
diff --git a/batctl/patches/0011-batctl-tcpdump-Fix-types-for-for-TT-v1.patch b/batctl/patches/0011-batctl-tcpdump-Fix-types-for-for-TT-v1.patch
new file mode 100644 (file)
index 0000000..a4553b7
--- /dev/null
@@ -0,0 +1,30 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:43 +0100
+Subject: [PATCH] batctl: tcpdump: Fix types for for TT v1
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/15a1335cadacc7c3bb4723a30617d123a961a311
+---
+ tcpdump.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/tcpdump.c b/tcpdump.c
+index db9c46afecf3de94dbd4d9292df1fe0812fb8bfc..da5541ea9f5f9f9b6fd0838d2242daa22d41a28d 100644
+--- a/tcpdump.c
++++ b/tcpdump.c
+@@ -157,7 +157,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;
diff --git a/batctl/patches/0012-batctl-Simplify-concatenation-of-pathnames.patch b/batctl/patches/0012-batctl-Simplify-concatenation-of-pathnames.patch
new file mode 100644 (file)
index 0000000..f07eb75
--- /dev/null
@@ -0,0 +1,58 @@
+From: Sven Eckelmann <sven.eckelmann@openmesh.com>
+Date: Thu, 23 Nov 2017 15:04:44 +0100
+Subject: [PATCH] batctl: Simplify concatenation of pathnames
+
+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 <sven.eckelmann@openmesh.com>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/cfaec23c5f6f2cf649f3e0673b2e0c61bc01969f
+---
+ 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 a4add34bbaf8c34f8357ba8d1583218fdaf4df93..66e8f05bd2277e5560be77a26b97245223fa72aa 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 676012bb56f9f8aa757b4805e27d904181ee2d27..1c96e6241d01b83a136ff135bee8dd780629f7aa 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);
diff --git a/batctl/patches/0013-batctl-Handle-allocation-error-in-vlan_get_link_pars.patch b/batctl/patches/0013-batctl-Handle-allocation-error-in-vlan_get_link_pars.patch
new file mode 100644 (file)
index 0000000..e772cae
--- /dev/null
@@ -0,0 +1,31 @@
+From: Sven Eckelmann <sven@narfation.org>
+Date: Sat, 2 Dec 2017 08:45:59 +0100
+Subject: [PATCH] batctl: Handle allocation error in vlan_get_link_parse
+
+The malloc could fail and return NULL. In this case, the processing of the
+current interface index has to be stopped to avoid writing to NULL (which
+would cause a segfault).
+
+Fixes: d29288fe0583 ("batctl: implement vlan-to-link helper functions")
+Signed-off-by: Sven Eckelmann <sven@narfation.org>
+Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
+
+Origin: upstream, https://git.open-mesh.org/batctl.git/commit/2ea390ce9bdda39d3c15bd9470009f56f42d5ed9
+---
+ functions.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/functions.c b/functions.c
+index 1c96e6241d01b83a136ff135bee8dd780629f7aa..f91f26f4045766474d5dc109d76e20afd91a7791 100644
+--- a/functions.c
++++ b/functions.c
+@@ -812,6 +812,9 @@ static int vlan_get_link_parse(struct nl_msg *msg, void *arg)
+       idx = *(int *)nla_data(tb[IFLA_LINK]);
+       free(nl_arg->iface);
+       nl_arg->iface = malloc(IFNAMSIZ + 1);
++      if (!nl_arg->iface)
++              goto err;
++
+       if (!if_indextoname(idx, nl_arg->iface))
+               goto err;