From 5596f7cdcdc1983021185c5e0900d5fcba7f3282 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sun, 30 Dec 2012 14:55:29 +0200 Subject: Check returns from pipe and dup2. --- src/preproc.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/preproc.c') diff --git a/src/preproc.c b/src/preproc.c index f1d5227..ce32a29 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -664,13 +664,18 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/ - pipe(pout); + if (pipe(pout)) { + grecs_error(NULL, errno, "pipe"); + return NULL; + } switch (pid = fork()) { /* The child branch. */ case 0: if (pout[1] != 1) { - close(1); - dup2(pout[1], 1); + if (dup2(pout[1], 1) == -1) { + grecs_error(NULL, errno, "dup2"); + exit(127); + } } /* Close unneeded descripitors */ @@ -684,13 +689,16 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) FILE *fp; signal(SIGCHLD, SIG_DFL); - pipe(p); + if (pipe(p)) { + grecs_error(NULL, errno, "pipe"); + exit(127); + } switch (pid = fork()) { /* Grandchild */ case 0: - if (p[1] != 2) { - close(2); - dup2(p[1], 2); + if (p[1] != 2 && dup2(p[1], 2) == -1) { + grecs_error(NULL, errno, "dup2"); + exit(127); } close(p[0]); -- cgit v1.2.1