]> granicus.if.org Git - sudo/commitdiff
Handle read() returning -1 when creating temporary files.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 May 2016 18:48:17 +0000 (12:48 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 May 2016 18:48:17 +0000 (12:48 -0600)
Coverity CID 104100

src/sudo_edit.c

index e8da7e11b33a7e7bbbfe5550019ce60dc1183392..0bae66ffc5017146b99818843639c74d7e23799f 100644 (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);
        }
        /*