The putnode() routine in fs2dt.c was not checking for errors returned from calls to read(). Add checks for these errors and abort the setup of printing from purgatory if the checks fail. Signed-off-by: Geoff Levand <geoff at infradead.org> --- kexec/fs2dt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c index 98d6cb4..242a15e 100644 --- a/kexec/fs2dt.c +++ b/kexec/fs2dt.c @@ -639,6 +639,11 @@ static void putnode(void) } result = read(fd, buff, statbuf.st_size); close(fd); + if (result <= 0) { + printf("Unable to read %s, printing from purgatory is diabled\n", + filename); + goto no_debug; + } strncpy(filename, "/proc/device-tree/", MAXPATH); strncat(filename, buff, MAXPATH); strncat(filename, "/compatible", MAXPATH); @@ -661,7 +666,8 @@ static void putnode(void) goto no_debug; } result = read(fd, buff, statbuf.st_size); - if (!strcmp(buff, "hvterm1") || !strcmp(buff, "hvterm-protocol")) + if (result && (!strcmp(buff, "hvterm1") + || !strcmp(buff, "hvterm-protocol"))) my_debug = 1; close(fd); free(buff); -- 1.8.1.2