Skip to contentSkip to conversation

kexec/fs2dt: Check for NULL pointer in dt_copy_old_root_param()

PATCH Applied Madhavan Srinivasan 3 participants 3 messages Oct 4, 2016 – Oct 7, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 kexec/fs2dt: Check for NULL pointer in dt_copy_old_root_param()

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

---
Changelog v2
-Removed redundant check fp

Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
kexec/fs2dt.c +14 -12
index 6ed2399759cf..79aa0f320a5a 100644
@@ -524,19 +524,21 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
-	if (fp) {
-		if (getline(&last_cmdline, &len, fp) == -1)
-			die("unable to read %s\n", filename);
-
-		p = strstr(last_cmdline, "root=");
-		if (p) {
-			old_param = strtok(p, " ");
-			len = strlen(local_cmdline);
-			if (len != 0)
-				strcat(local_cmdline, " ");
-			strcat(local_cmdline, old_param);
-		}
+	if (!fp)
+		return;
+
+	if (getline(&last_cmdline, &len, fp) == -1)
+		die("unable to read %s\n", filename);
+
+	p = strstr(last_cmdline, "root=");
+	if (p) {
+		old_param = strtok(p, " ");
+		len = strlen(local_cmdline);
+		if (len != 0)
+			strcat(local_cmdline, " ");
+		strcat(local_cmdline, old_param);
 	}
+
 	if (last_cmdline)
 		free(last_cmdline);
 
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Reviewed-by on v3 1/1
#2 lore raw
In reply to Madhavan Srinivasan
Quoted 62 lines · Madhavan Srinivasan

In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same.

---
Changelog v2
-Removed redundant check fp

Changelog v1:
- Moved the check right after fopen

 kexec/fs2dt.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
kexec/fs2dt.c +14 -12
index 6ed2399759cf..79aa0f320a5a 100644
@@ -524,19 +524,21 @@ static void dt_copy_old_root_param(void)
 	strcpy(filename, pathname);
 	strcat(filename, "bootargs");
 	fp = fopen(filename, "r");
-	if (fp) {
-		if (getline(&last_cmdline, &len, fp) == -1)
-			die("unable to read %s\n", filename);
-
-		p = strstr(last_cmdline, "root=");
-		if (p) {
-			old_param = strtok(p, " ");
-			len = strlen(local_cmdline);
-			if (len != 0)
-				strcat(local_cmdline, " ");
-			strcat(local_cmdline, old_param);
-		}
+	if (!fp)
+		return;
+
+	if (getline(&last_cmdline, &len, fp) == -1)
+		die("unable to read %s\n", filename);
+
+	p = strstr(last_cmdline, "root=");
+	if (p) {
+		old_param = strtok(p, " ");
+		len = strlen(local_cmdline);
+		if (len != 0)
+			strcat(local_cmdline, " ");
+		strcat(local_cmdline, old_param);
 	}
+
 	if (last_cmdline)
 		free(last_cmdline);
 
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Thanks
Dave

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec