[03/10] batctl: Handle allocation error for path_buff

Message ID 20171123140444.17119-4-sven.eckelmann@openmesh.com (mailing list archive)
State Accepted, archived
Commit 3b52283a5f60d1c6ec11628d031e72f0a28a720f
Delegated to: Simon Wunderlich
Headers
Series batctl: Fixes and minor cleanup |

Commit Message

Sven Eckelmann Nov. 23, 2017, 2:04 p.m. UTC
  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(+)
  

Patch

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