aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2015-08-03 12:02:17 +0200
committerCorinna Vinschen <corinna@vinschen.de>2015-08-03 12:02:17 +0200
commitfe244117709854cd60d6c7974c595659516a713c (patch)
tree9be39e8c046e45a87cd3447a59920ccb887ddc1c /winsup
parent6fc911071f9389e4ed5b287d35c91f352cbeda43 (diff)
downloadnewlib-fe244117709854cd60d6c7974c595659516a713c.zip
newlib-fe244117709854cd60d6c7974c595659516a713c.tar.gz
newlib-fe244117709854cd60d6c7974c595659516a713c.tar.bz2
strace: Handle ofile descriptor more carefully.cygwin-2_2_0-release
Fix coverity CIDs 128250 - 128252 * strace.cc (main2): Don't call setvbuf on NULL descriptor. Explicitely fclose ofile. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/utils/ChangeLog5
-rw-r--r--winsup/utils/strace.cc14
2 files changed, 13 insertions, 6 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 21a7c49..e317ae3 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-03 Corinna Vinschen <corinna@vinschen.de>
+
+ * strace.cc (main2): Don't call setvbuf on NULL descriptor.
+ Explicitely fclose ofile.
+
2015-07-29 Corinna Vinschen <corinna@vinschen.de>
* strace.cc (main2): Rename from main.
diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
index 4c0c04f..f9c6644 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