[PATCH 2/6] pipeio: Fix error handling in fwts_pipe_exec
Jeremy Kerr
jk at ozlabs.org
Fri Apr 22 05:41:08 UTC 2016
Currently, fwts_pipe_exec does not handle failures from fwts_pipe_read,
and will end up dereferencing a NULL pointer on failure.
This change implements error handling for this case.
Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
---
src/lib/src/fwts_pipeio.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
index 75addc5..7148903 100644
--- a/src/lib/src/fwts_pipeio.c
+++ b/src/lib/src/fwts_pipeio.c
@@ -156,20 +156,25 @@ int fwts_pipe_close(const int fd, const pid_t pid)
int fwts_pipe_exec(const char *command, fwts_list **list, int *status)
{
pid_t pid;
- int fd;
+ int rc, fd;
ssize_t len;
char *text;
if ((fd = fwts_pipe_open(command, &pid)) < 0)
return FWTS_ERROR;
- fwts_pipe_read(fd, &text, &len);
- *list = fwts_list_from_text(text);
- free(text);
+ rc = fwts_pipe_read(fd, &text, &len);
+ if (!rc && len > 0) {
+ *list = fwts_list_from_text(text);
+ free(text);
+ } else {
+ list = NULL;
+ }
*status = fwts_pipe_close(fd, pid);
- if (*status) {
- fwts_list_free(*list, free);
+ if (rc || *status) {
+ if (*list)
+ fwts_list_free(*list, free);
*list = NULL;
return FWTS_EXEC_ERROR;
}
--
2.5.0
More information about the fwts-devel
mailing list