Handle read() returning -1 when creating temporary files.
Coverity CID 104100
This commit is contained in:
@@ -559,17 +559,22 @@ sudo_edit_create_tfiles(struct command_details *command_details,
|
|||||||
debug_return_int(-1);
|
debug_return_int(-1);
|
||||||
}
|
}
|
||||||
if (ofd != -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 = write(tfd, buf, nread)) != nread) {
|
||||||
if (nwritten == -1)
|
if (nwritten == -1)
|
||||||
sudo_warn("%s", tf[j].tfile);
|
sudo_warn("%s", tf[j].tfile);
|
||||||
else
|
else
|
||||||
sudo_warnx(U_("%s: short write"), tf[j].tfile);
|
sudo_warnx(U_("%s: short write"), tf[j].tfile);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nread != 0) {
|
||||||
|
if (nread < 0)
|
||||||
|
sudo_warn("%s", files[i]);
|
||||||
close(ofd);
|
close(ofd);
|
||||||
close(tfd);
|
close(tfd);
|
||||||
debug_return_int(-1);
|
debug_return_int(-1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
close(ofd);
|
close(ofd);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user