]> diplodocus.org Git - nmh/commitdiff
Added check to get_file_info() in attach.c for failed fgets() call.
authorDavid Levine <levinedl@acm.org>
Wed, 15 Jan 2014 02:09:40 +0000 (20:09 -0600)
committerDavid Levine <levinedl@acm.org>
Wed, 15 Jan 2014 02:09:40 +0000 (20:09 -0600)
It can happen on Cygwin for mysterious reasons,
http://cygwin.com/faq/faq.html#faq.using.bloda.

uip/attach.c
uip/whatnowsbr.c

index b1a4f441ca5a2cc72dcb24958cffc168d0c0d87e..333cda663bb00a2e2cfc7665f4b36d5d16d61c9a 100644 (file)
@@ -327,10 +327,8 @@ mime_type(const char *file_name) {
  */
 static char *
 get_file_info(const char *proc, const char *file_name) {
  */
 static char *
 get_file_info(const char *proc, const char *file_name) {
-    char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
     char *cmd, *cp;
     char *quotec = "'";
     char *cmd, *cp;
     char *quotec = "'";
-    FILE *fp;
 
     if ((cp = strchr(file_name, '\''))) {
         /* file_name contains a single quote. */
 
     if ((cp = strchr(file_name, '\''))) {
         /* file_name contains a single quote. */
@@ -345,7 +343,12 @@ get_file_info(const char *proc, const char *file_name) {
 
     cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
     if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
 
     cmd = concat(proc, " ", quotec, file_name, quotec, NULL);
     if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) {
+        FILE *fp;
+
         if ((fp = popen(cmd, "r")) != NULL) {
         if ((fp = popen(cmd, "r")) != NULL) {
+            char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
+
+            buf[0] = '\0';
             if (fgets(buf, sizeof buf, fp)) {
                 char *eol;
 
             if (fgets(buf, sizeof buf, fp)) {
                 char *eol;
 
@@ -363,8 +366,12 @@ get_file_info(const char *proc, const char *file_name) {
                 if ((eol = strpbrk(cp, "\n\r")) != NULL) {
                     *eol = '\0';
                 }
                 if ((eol = strpbrk(cp, "\n\r")) != NULL) {
                     *eol = '\0';
                 }
-            } else {
-                advise(NULL, "unable to read mime type");
+            } else if (buf[0] == '\0') {
+                /* This can happen on Cygwin if the popen()
+                   mysteriously fails.  Return NULL so that the caller
+                   will use another method to determine the info. */
+                free (cp);
+                cp = NULL;
             }
 
             (void) pclose(fp);
             }
 
             (void) pclose(fp);
index 7b20925a055d98707f87cfbdaa5f65d170f9cfc3..82b0d67fdcf10e2e6464a8fa42f7769e78eec3e3 100644 (file)
@@ -426,7 +426,7 @@ WhatNow (int argc, char **argv)
                        ++ap;
                        if ((attachformat = atoi(*ap)) > 2) {
                            advise(NULL,
                        ++ap;
                        if ((attachformat = atoi(*ap)) > 2) {
                            advise(NULL,
-                                  "ingoring invalid attachformat value of %d",
+                                  "ignoring invalid attachformat value of %d",
                                   attachformat);
                            attachformat = 1;
                        }
                                   attachformat);
                            attachformat = 1;
                        }