Though very unlikely that realloc will fail here, its return value
should be checked.
Fixes: 41646a9a40a7 ("tools: jailhouse: reimplement jailhouse-cell-list in C")
Signed-off-by: Ralf Ramsauer <[email protected]>
---
tools/jailhouse.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/jailhouse.c b/tools/jailhouse.c
index 82f2e1ac41..c23bb3bda7 100644
--- a/tools/jailhouse.c
+++ b/tools/jailhouse.c
@@ -209,8 +209,13 @@ static char *read_sysfs_cell_string(const unsigned int id,
const char *entry)
/* chop trailing linefeeds and enforce the string to be
* null-terminated */
- if (ret[size-1] != '\n')
+ if (ret[size-1] != '\n') {
ret = realloc(ret, ++size);
+ if (ret == NULL) {
+ fprintf(stderr, "insufficient memory\n");
+ exit(1);
+ }
+ }
ret[size-1] = 0;
return ret;
--
2.12.0
--
You received this message because you are subscribed to the Google Groups
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.