forked from osmocom/wireshark
dup() can fail; check whether it does.
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.
This commit is contained in:
parent
85a7938925
commit
165792fb31
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue