[B.A.T.M.A.N.] [PATCH 03/10] batctl: Handle allocation error for path_buff

Sven Eckelmann
2017-11-23T14:04:37Z

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>
---
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) {
--
2.11.0