diff mbox series

[6/6] core/utils: fix missing NULL return value check

Message ID 20220530060304.1296389-7-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series Fix gcc warnings or -fanalyzer warnings | expand

Commit Message

Dominique Martinet May 30, 2022, 6:03 a.m. UTC
in case of allocation failures string_split or strdup could return NULL.
This is not actually possible on default linux, but static analysis is always
noisy about these...

Reported-by: gcc -fanalyzer
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/util.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index d9df906f090f..3724182f1e4d 100644
--- a/core/util.c
+++ b/core/util.c
@@ -979,6 +979,10 @@  static char *getroot_abs_path(char* devname)
 {
 	int fd;
 	char *path;
+
+	if (!devname)
+		return NULL;
+
 	if ((path = realpath(devname, NULL))) {
 		if ((fd = open(path, O_RDWR | O_CLOEXEC)) != -1) {
 			(void)close(fd);
@@ -1120,6 +1124,8 @@  static char *get_root_from_cmdline(void)
 
 	if (ret > 0) {
 		parms = string_split(buf, ' ');
+		if (!parms)
+			goto out;
 		int nparms = count_string_array((const char **)parms);
 		for (unsigned int index = 0; index < nparms; index++) {
 			if (!strncmp(parms[index], "root=", strlen("root="))) {
@@ -1132,6 +1138,7 @@  static char *get_root_from_cmdline(void)
 			}
 		}
 	}
+out:
 	fclose(fp);
 	free_string_array(parms);
 	free(buf);
@@ -1181,6 +1188,8 @@  int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset,
 	}
 
 	char **lines = string_split(buf, '\n');
+	if (!lines)
+		return -errno;
 	int nlines = count_string_array((const char **)lines);
 	/*
 	 * If the buffer is full and there is only one line,