1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-19 14:50:07 +03:00

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
This commit is contained in:
Philip Withnall 2014-08-24 23:10:13 +01:00 committed by Daniel Veillard
parent 98d71f9191
commit 21699937b0

View File

@ -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 */
}