]> diplodocus.org Git - nmh/commitdiff
Check return values of system calls in several sbr .c files, found
authorDavid Levine <levinedl@acm.org>
Tue, 26 Aug 2014 03:06:11 +0000 (22:06 -0500)
committerDavid Levine <levinedl@acm.org>
Tue, 26 Aug 2014 03:06:11 +0000 (22:06 -0500)
with gcc's -D_FORTIFY_SOURCE=2.  Updated checks added previously to
mhfixmsg.c to be consistent.

sbr/error.c
sbr/m_draft.c
sbr/push.c
sbr/ruserpass.c
sbr/seq_save.c
sbr/utils.c
uip/mhfixmsg.c

index fd74d27..0b6d777 100644 (file)
@@ -106,5 +106,7 @@ advertise (char *what, char *tail, char *fmt, va_list ap)
     }
     iov->iov_len = strlen (iov->iov_base = "\n");
     iov++;
     }
     iov->iov_len = strlen (iov->iov_base = "\n");
     iov++;
-    writev (fileno (stderr), iob, iov - iob);
+    if (writev (fileno (stderr), iob, iov - iob) < 0) {
+       advise ("stderr", "writev");
+    }
 }
 }
index 9d28606..de5ac5c 100644 (file)
@@ -29,7 +29,9 @@ m_draft (char *folder, char *msg, int use, int *isdf)
     }
     *isdf = 1;
     
     }
     *isdf = 1;
     
-    chdir (m_maildir (""));
+    if (chdir (m_maildir ("")) < 0) {
+       advise (m_maildir (""), "chdir");
+    }
     strncpy (buffer, m_maildir (folder), sizeof(buffer));
 
     create_folder (buffer, 0, done);
     strncpy (buffer, m_maildir (folder), sizeof(buffer));
 
     create_folder (buffer, 0, done);
index 39c58ac..c4d0e40 100644 (file)
@@ -40,8 +40,12 @@ push(void)
 
            unregister_for_removal(0);
 
 
            unregister_for_removal(0);
 
-           freopen ("/dev/null", "r", stdin);
-           freopen ("/dev/null", "w", stdout);
+           if (freopen ("/dev/null", "r", stdin) == NULL) {
+               advise ("stdin", "freopen");
+            }
+           if (freopen ("/dev/null", "w", stdout) == NULL) {
+               advise ("stdout", "freopen");
+            }
            break;
 
        default:
            break;
 
        default:
index 7669f8b..a55f680 100644 (file)
@@ -148,7 +148,9 @@ ruserpass(char *host, char **aname, char **apass)
        }
        printf("Name (%s:%s): ", host, myname);
 
        }
        printf("Name (%s:%s): ", host, myname);
 
-       fgets(tmp, sizeof(tmp) - 1, stdin);
+       if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
+           advise ("tmp", "fgets");
+       }
        tmp[strlen(tmp) - 1] = '\0';
        if (*tmp != '\0') {
            myname = tmp;
        tmp[strlen(tmp) - 1] = '\0';
        if (*tmp != '\0') {
            myname = tmp;
index 5148f74..8ac3086 100644 (file)
@@ -91,7 +91,9 @@ priv:
                    free(mp->seqname);
                    mp->seqname = NULL;
                    rewind(fp);
                    free(mp->seqname);
                    mp->seqname = NULL;
                    rewind(fp);
-                   ftruncate(fileno(fp), 0);
+                   if (ftruncate(fileno(fp), 0) < 0) {
+                       advise ("sequence file", "ftruncate");
+                   }
                } else if ((fp = lkfopendata (seqfile, "w", &failed_to_lock))
                           == NULL
                        && (m_unlink (seqfile) == -1 ||
                } else if ((fp = lkfopendata (seqfile, "w", &failed_to_lock))
                           == NULL
                        && (m_unlink (seqfile) == -1 ||
index 610f790..9dece99 100644 (file)
@@ -79,7 +79,9 @@ pwd(void)
         if (!mypath || !*mypath
                 || (strcpy (curwd, mypath), chdir (curwd)) == -1) {
             strcpy (curwd, "/");
         if (!mypath || !*mypath
                 || (strcpy (curwd, mypath), chdir (curwd)) == -1) {
             strcpy (curwd, "/");
-            chdir (curwd);
+            if (chdir (curwd) < 0) {
+                advise (curwd, "chdir");
+            }
         }
         return curwd;
     }
         }
         return curwd;
     }
index 5625380..5385b9e 100644 (file)
@@ -1646,16 +1646,16 @@ strip_crs (CT ct, int *message_mods) {
                         } else if (last_char_was_cr) {
                             if (*cp != '\n') {
                                 if (write (fd, "\r", 1) < 0) {
                         } else if (last_char_was_cr) {
                             if (*cp != '\n') {
                                 if (write (fd, "\r", 1) < 0) {
-                                    advise (tempfile, "write of CR failed");
+                                    advise (tempfile, "CR write");
                                 }
                             }
                             if (write (fd, cp, 1) < 0) {
                                 }
                             }
                             if (write (fd, cp, 1) < 0) {
-                                advise (tempfile, "write failed");
+                                advise (tempfile, "write");
                             }
                             last_char_was_cr = 0;
                         } else {
                             if (write (fd, cp, 1) < 0) {
                             }
                             last_char_was_cr = 0;
                         } else {
                             if (write (fd, cp, 1) < 0) {
-                                advise (tempfile, "write failed");
+                                advise (tempfile, "write");
                             }
                             last_char_was_cr = 0;
                         }
                             }
                             last_char_was_cr = 0;
                         }