[PATCH] lib: fwts_alloc: only parse mem info once we have a valid line read in
Colin King
colin.king at canonical.com
Mon Jun 5 13:40:40 UTC 2017
From: Colin Ian King <colin.king at canonical.com>
It has been observed that the sscanf without the expected input format can
make the scanning loop spin forever. The easiest way around is to read
in entire lines and sscan each line so that way we at least hit the end of
file marker no matter what.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_alloc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/lib/src/fwts_alloc.c b/src/lib/src/fwts_alloc.c
index c0d5e555..e65b181e 100644
--- a/src/lib/src/fwts_alloc.c
+++ b/src/lib/src/fwts_alloc.c
@@ -234,6 +234,7 @@ static void *fwts_low_mmap(const size_t requested_size)
{
FILE *fp;
char pathname[1024];
+ char buffer[4096];
void *addr_start;
void *addr_end;
void *last_addr_end = NULL;
@@ -251,8 +252,8 @@ static void *fwts_low_mmap(const size_t requested_size)
if (!fp)
return fwts_low_mmap_walkdown(requested_size);
- while (!feof(fp)) {
- if (fscanf(fp, "%p-%p %*s %*x %*s %*u %1023s\n",
+ while (fgets(buffer, sizeof(buffer) - 1, fp)) {
+ if (sscanf(buffer, "%p-%p %*s %*x %*s %*u %1023s\n",
&addr_start, &addr_end, pathname) != 3)
continue;
/*
--
2.11.0
More information about the fwts-devel
mailing list