Skip to contentSkip to conversation

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

PATCH Superseded Madhavan Srinivasan 4 participants 5 messages Sep 23, 2016 – Sep 29, 2016

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 adds a check.

---
 kexec/fs2dt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kexec/fs2dt.c +2 -1
index 6ed2399759cf..2c1ebdf525f4 100644
@@ -540,7 +540,8 @@ static void dt_copy_old_root_param(void)
 	if (last_cmdline)
 		free(last_cmdline);
 
-	fclose(fp);
+	if (fp)
+		fclose(fp);
 }
 
 /*
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 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 adds a check.

---
 kexec/fs2dt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kexec/fs2dt.c +2 -1
index 6ed2399759cf..2c1ebdf525f4 100644
@@ -540,7 +540,8 @@ static void dt_copy_old_root_param(void)
 	if (last_cmdline)
 		free(last_cmdline);
 
-	fclose(fp);
+	if (fp)
+		fclose(fp);
 }
 
 /*
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

#2 lore raw
In reply to Madhavan Srinivasan
Quoted 15 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 adds a check.

---
 kexec/fs2dt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kexec/fs2dt.c +0 -0
index 6ed2399759cf..2c1ebdf525f4 100644

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 544

Quoted 6 lines
kexec/fs2dt.c +2 -1
@@ -540,7 +540,8 @@ static void dt_copy_old_root_param(void)
 	if (last_cmdline)
 		free(last_cmdline);
 
-	fclose(fp);
+	if (fp)
+		fclose(fp);

Looks fine, however a better practise could be to return just after fopen() if fp was null.

~Pratyush

Quoted 11 lines
kexec/fs2dt.c +0 -0
 }
 
 /*
Signature · 7 lines
2.7.4


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

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

#3 lore raw
Quoted 19 lines · Pratyush Anand
Quoted 18 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 adds a check.

---
 kexec/fs2dt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kexec/fs2dt.c +0 -0
index 6ed2399759cf..2c1ebdf525f4 100644
@@ -540,7 +540,8 @@ static void dt_copy_old_root_param(void)
 	if (last_cmdline)
 		free(last_cmdline);
 
Quoted 6 lines

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 544

Quoted 3 lines
kexec/fs2dt.c +2 -1
-	fclose(fp);
+	if (fp)
+		fclose(fp);

Looks fine, however a better practise could be to return just after fopen() if fp was null.

That sounds like it would be somewhat cleaner.
Madhavan, could you see about making it so?

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

#4 lore raw
Quoted 20 lines · Simon Horman
Quoted 19 lines · Pratyush Anand
Quoted 18 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 adds a check.

---
  kexec/fs2dt.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
kexec/fs2dt.c +0 -0
index 6ed2399759cf..2c1ebdf525f4 100644
@@ -540,7 +540,8 @@ static void dt_copy_old_root_param(void)
  	if (last_cmdline)
  		free(last_cmdline);
 
Quoted 7 lines
Quoted 5 lines

kexec/fs2dt.c static void dt_copy_old_root_param(void) · line 544

Quoted 3 lines
kexec/fs2dt.c +2 -1
-	fclose(fp);
+	if (fp)
+		fclose(fp);

Looks fine, however a better practise could be to return just after fopen() if fp was null.

That sounds like it would be somewhat cleaner.
Madhavan, could you see about making it so?

Yep. re-spinning now.

Maddy

Quoted 1 line

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