]> diplodocus.org Git - nmh/commitdiff
Checked return value of write() calls in mhfixmsg.c,
authorDavid Levine <levinedl@acm.org>
Sun, 17 Aug 2014 02:01:26 +0000 (21:01 -0500)
committerDavid Levine <levinedl@acm.org>
Sun, 17 Aug 2014 02:01:26 +0000 (21:01 -0500)
found with gcc's -D_FORTIFY_SOURCE=2.

uip/mhfixmsg.c

index 2a705114e0fe8cb95e3e5db7c31ec457c3f47d82..f5488532bfa7df9f6ac05a40cf7b4852a05a9d2d 100644 (file)
@@ -287,11 +287,12 @@ main (int argc, char **argv) {
             }
         }
 
             }
         }
 
-        if (! (cts = (CT *) calloc ((size_t) 2, sizeof *cts)))
+        if (! (cts = (CT *) calloc ((size_t) 2, sizeof *cts))) {
             adios (NULL, "out of memory");
             adios (NULL, "out of memory");
+        }
         ctp = cts;
 
         ctp = cts;
 
-        if ((ct = parse_mime (file))) *ctp++ = ct;
+        if ((ct = parse_mime (file))) { *ctp++ = ct; }
     } else {
         /*
          * message(s) are coming from a folder
     } else {
         /*
          * message(s) are coming from a folder
@@ -321,8 +322,9 @@ main (int argc, char **argv) {
                 done (1);
         seq_setprev (mp);       /* set the previous-sequence */
 
                 done (1);
         seq_setprev (mp);       /* set the previous-sequence */
 
-        if (! (cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof *cts)))
+        if (! (cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof *cts))) {
             adios (NULL, "out of memory");
             adios (NULL, "out of memory");
+        }
         ctp = cts;
 
         for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
         ctp = cts;
 
         for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -330,7 +332,7 @@ main (int argc, char **argv) {
                 char *msgnam;
 
                 msgnam = m_name (msgnum);
                 char *msgnam;
 
                 msgnam = m_name (msgnum);
-                if ((ct = parse_mime (msgnam))) *ctp++ = ct;
+                if ((ct = parse_mime (msgnam))) { *ctp++ = ct; }
             }
         }
 
             }
         }
 
@@ -446,7 +448,7 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
     }
 
     if (modify_inplace) {
     }
 
     if (modify_inplace) {
-        if (status != OK) (void) m_unlink (outfile);
+        if (status != OK) { (void) m_unlink (outfile); }
         free (outfile);
         outfile = NULL;
     }
         free (outfile);
         outfile = NULL;
     }
@@ -846,7 +848,7 @@ ensure_text_plain (CT *ct, CT parent, int *message_mods, int replacetextplain) {
         int has_text_plain = 0;
 
         /* Nothing to do for text/plain. */
         int has_text_plain = 0;
 
         /* Nothing to do for text/plain. */
-        if ((*ct)->c_subtype == TEXT_PLAIN) return OK;
+        if ((*ct)->c_subtype == TEXT_PLAIN) { return OK; }
 
         if (parent  &&  parent->c_type == CT_MULTIPART  &&
             parent->c_subtype == MULTI_ALTERNATE) {
 
         if (parent  &&  parent->c_type == CT_MULTIPART  &&
             parent->c_subtype == MULTI_ALTERNATE) {
@@ -1630,7 +1632,7 @@ strip_crs (CT ct, int *message_mods) {
                 size_t i;
                 int last_char_was_cr = 0;
 
                 size_t i;
                 int last_char_was_cr = 0;
 
-                if (end > 0) bytes_to_read -= bytes_read;
+                if (end > 0) { bytes_to_read -= bytes_read; }
 
                 for (i = 0, cp = buffer; i < bytes_read; ++i, ++cp) {
                     if (*cp == '\n'  &&  last_char_was_cr) {
 
                 for (i = 0, cp = buffer; i < bytes_read; ++i, ++cp) {
                     if (*cp == '\n'  &&  last_char_was_cr) {
@@ -1665,11 +1667,19 @@ strip_crs (CT ct, int *message_mods) {
                         if (*cp == '\r') {
                             last_char_was_cr = 1;
                         } else if (last_char_was_cr) {
                         if (*cp == '\r') {
                             last_char_was_cr = 1;
                         } else if (last_char_was_cr) {
-                            if (*cp != '\n') write (fd, "\r", 1);
-                            write (fd, cp, 1);
+                            if (*cp != '\n') {
+                                if (write (fd, "\r", 1) < 0) {
+                                    advise (tempfile, "write of CR failed");
+                                }
+                            }
+                            if (write (fd, cp, 1) < 0) {
+                                advise (tempfile, "write failed");
+                            }
                             last_char_was_cr = 0;
                         } else {
                             last_char_was_cr = 0;
                         } else {
-                            write (fd, cp, 1);
+                            if (write (fd, cp, 1) < 0) {
+                                advise (tempfile, "write failed");
+                            }
                             last_char_was_cr = 0;
                         }
                     }
                             last_char_was_cr = 0;
                         }
                     }
@@ -1797,8 +1807,8 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
                                 }
                             }
                         }
                                 }
                             }
                         }
-                        if (new != -1) close (new);
-                        if (old != -1) close (old);
+                        if (new != -1) { close (new); }
+                        if (old != -1) { close (old); }
                         (void) m_unlink (outfile);
 
                         if (i < 0) {
                         (void) m_unlink (outfile);
 
                         if (i < 0) {