Skip to content

Commit

Permalink
dup() can fail; check whether it does.
Browse files Browse the repository at this point in the history
If, for example, you run out of file descriptors, dup() can fail, and
ws_dup() is a wrapper around it on UN*X.  Don't just pass the result of
ws_dup() to ws_fdopen(); instead, save its result, check against -1 and,
if it's -1, give up, otherwise pass it to ws_fdopen().

This addresses Coverity CID 1471708.

Also, if ws_fdopen() fails, close the descriptor we got from ws_dup();
this closes a possible FD leak.
  • Loading branch information
guyharris committed Jan 19, 2021
1 parent 85a7938 commit 165792f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ui/qt/endpoint_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,17 @@ QUrl EndpointDialog::createMap(bool json_only)
return QUrl();
}
// duplicate file descriptor as it is not allowed to perform a fclose before closing QFile
FILE* fp = ws_fdopen(ws_dup(fd), "wb");
int duped_fd = ws_dup(fd);
if (duped_fd == -1) {
QMessageBox::warning(this, tr("Map file error"), tr("Unable to create temporary file"));
g_free(hosts);
return QUrl();
}
FILE* fp = ws_fdopen(duped_fd, "wb");
if (fp == NULL) {
QMessageBox::warning(this, tr("Map file error"), tr("Unable to create temporary file"));
g_free(hosts);
ws_close(duped_fd);
return QUrl();
}

Expand Down

0 comments on commit 165792f

Please sign in to comment.