Commit 21699937 authored by Philip Withnall's avatar Philip Withnall Committed by Daniel Veillard

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
parent 98d71f91
......@@ -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 */
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment