[newlib-cygwin] strace: Handle ofile descriptor more carefully.
Corinna Vinschen
corinna@sourceware.org
Mon Aug 3 10:02:00 GMT 2015
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fe244117709854cd60d6c7974c595659516a713c
commit fe244117709854cd60d6c7974c595659516a713c
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Mon Aug 3 12:02:17 2015 +0200
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 <corinna@vinschen.de>
Diff:
---
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 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
More information about the Cygwin-cvs
mailing list