From: David Levine Date: Wed, 15 Jan 2014 02:09:40 +0000 (-0600) Subject: Added check to get_file_info() in attach.c for failed fgets() call. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/0c50c6698d3fee84b18f11b3affdffbe59011c2c?ds=sidebyside;hp=-c Added check to get_file_info() in attach.c for failed fgets() call. It can happen on Cygwin for mysterious reasons, http://cygwin.com/faq/faq.html#faq.using.bloda. --- 0c50c6698d3fee84b18f11b3affdffbe59011c2c diff --git a/uip/attach.c b/uip/attach.c index b1a4f441..333cda66 100644 --- a/uip/attach.c +++ b/uip/attach.c @@ -327,10 +327,8 @@ mime_type(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 = "'"; - FILE *fp; 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))) { + FILE *fp; + if ((fp = popen(cmd, "r")) != NULL) { + char buf[BUFSIZ >= 2048 ? BUFSIZ : 2048]; + + buf[0] = '\0'; 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'; } - } 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); diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 7b20925a..82b0d67f 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -426,7 +426,7 @@ WhatNow (int argc, char **argv) ++ap; if ((attachformat = atoi(*ap)) > 2) { advise(NULL, - "ingoring invalid attachformat value of %d", + "ignoring invalid attachformat value of %d", attachformat); attachformat = 1; }