Handle read() returning -1 when creating temporary files.

Coverity CID 104100
This commit is contained in:
Todd C. Miller
2016-05-04 12:48:17 -06:00
parent 20ff6023aa
commit 6ea903623b

View File

@@ -559,17 +559,22 @@ sudo_edit_create_tfiles(struct command_details *command_details,
debug_return_int(-1);
}
if (ofd != -1) {
while ((nread = read(ofd, buf, sizeof(buf))) != 0) {
while ((nread = read(ofd, buf, sizeof(buf))) > 0) {
if ((nwritten = write(tfd, buf, nread)) != nread) {
if (nwritten == -1)
sudo_warn("%s", tf[j].tfile);
else
sudo_warnx(U_("%s: short write"), tf[j].tfile);
close(ofd);
close(tfd);
debug_return_int(-1);
break;
}
}
if (nread != 0) {
if (nread < 0)
sudo_warn("%s", files[i]);
close(ofd);
close(tfd);
debug_return_int(-1);
}
close(ofd);
}
/*