From 6bd7a0e8caa98eea328a8491ce099f9314c2af44 Mon Sep 17 00:00:00 2001 From: Geoff Levand Date: Thu, 3 Oct 2013 20:19:34 +0000 Subject: kexec: Handle read errors in fs2dt setup 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 Signed-off-by: Simon Horman --- 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); -- cgit