From fe244117709854cd60d6c7974c595659516a713c Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 3 Aug 2015 12:02:17 +0200 Subject: [PATCH] strace: Handle ofile descriptor more carefully. Fix coverity CIDs 128250 - 128252 * strace.cc (main2): Don't call setvbuf on NULL descriptor. Explicitely fclose ofile. Signed-off-by: Corinna Vinschen --- winsup/utils/ChangeLog | 5 +++++ winsup/utils/strace.cc | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 21a7c4915..e317ae30a 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,8 @@ +2015-08-03 Corinna Vinschen + + * strace.cc (main2): Don't call setvbuf on NULL descriptor. + Explicitely fclose ofile. + 2015-07-29 Corinna Vinschen * strace.cc (main2): Rename from main. diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc index 4c0c04f1f..f9c6644b6 100644 --- a/winsup/utils/strace.cc +++ b/winsup/utils/strace.cc @@ -1034,6 +1034,7 @@ main2 (int argc, char **argv) int opt; int toggle = 0; int sawquiet = -1; + DWORD ret = 0; if (load_cygwin ()) { @@ -1147,23 +1148,24 @@ character #%d.\n", optarg, (int) (endptr - optarg), endptr); if (!mask) mask = _STRACE_ALL; - if (bufsize) - setvbuf (ofile, (char *) alloca (bufsize), _IOFBF, bufsize); - if (!ofile) ofile = stdout; + if (bufsize) + setvbuf (ofile, (char *) alloca (bufsize), _IOFBF, bufsize); + if (toggle) dotoggle (pid); else { drive_map = (void *) cygwin_internal (CW_ALLOC_DRIVE_MAP); - DWORD ret = dostrace (mask, ofile, pid, argv + optind); + ret = dostrace (mask, ofile, pid, argv + optind); if (drive_map) cygwin_internal (CW_FREE_DRIVE_MAP, drive_map); - ExitProcess (ret); } - return 0; + if (ofile && ofile != stdout) + fclose (ofile); + ExitProcess (ret); } int