diff options
author | Madhavan Srinivasan <maddy@linux.vnet.ibm.com> | 2016-10-04 07:07:05 +0530 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2016-10-07 11:56:29 +0900 |
commit | 16fd64af363b8cf7a3257d408327092db5f98695 (patch) | |
tree | cf5a275f0c46286516ef3afbe26226f604b3d9ae | |
parent | 6e8804f9ca67bee65aedd5e1cdf504737ab5c7ed (diff) |
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.
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r-- | kexec/fs2dt.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c index 6ed2399..79aa0f3 100644 --- a/kexec/fs2dt.c +++ b/kexec/fs2dt.c @@ -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); |