[libxml2] xmlIO: Handle error returns from dup()



commit 21699937b0db0da004401c9571ef10203ec134b2
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sun Aug 24 23:10:13 2014 +0100

    xmlIO: Handle error returns from dup()
    
    If dup() fails and returns -1, gzdopen() will transparently return NULL,
    but then close() will fail after being called on an invalid FD. Change
    the code to only call close() on valid FDs.
    
    Coverity issue: #72382

 xmlIO.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/xmlIO.c b/xmlIO.c
index c8258e5..0e1092d 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -1158,7 +1158,7 @@ xmlGzfileOpen_real (const char *filename) {
     if (!strcmp(filename, "-")) {
         int duped_fd = dup(fileno(stdin));
         fd = gzdopen(duped_fd, "rb");
-        if (fd == Z_NULL) {
+        if (fd == Z_NULL && duped_fd >= 0) {
             close(duped_fd);  /* gzdOpen() does not close on failure */
         }
 
@@ -1237,7 +1237,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
     if (!strcmp(filename, "-")) {
         int duped_fd = dup(fileno(stdout));
         fd = gzdopen(duped_fd, "rb");
-        if (fd == Z_NULL) {
+        if (fd == Z_NULL && duped_fd >= 0) {
             close(duped_fd);  /* gzdOpen() does not close on failure */
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]