]> granicus.if.org Git - mutt/commitdiff
Add typelen parameter to rfc1524_mailcap_lookup().
authorKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 11:17:09 +0000 (19:17 +0800)
committerKevin McCarthy <kevin@8t8.us>
Wed, 23 Oct 2019 11:17:09 +0000 (19:17 +0800)
Because of mime_lookup commands, the call to mutt_check_lookup_list()
inside the function can modify the passed in type.  Add an explicit
length parameter to the function, rather than assume the parameter
size.  This also makes it more evident the type parameter can be
modified to callers.

Change the len parameter to mutt_check_lookup_list() to type size_t,
just to be correct about it.

attach.c
handler.c
protos.h
recvattach.c
rfc1524.c
rfc1524.h

index de32d1fbdfb4271f63dc96d52ffe241cbf0b78ff..5e9906f5d487aeca5e1fad8528f814490539d5f5 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -58,7 +58,7 @@ int mutt_get_tmp_attachment (BODY *a)
   entry = rfc1524_new_entry();
 
   snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype);
-  rfc1524_mailcap_lookup(a, type, entry, 0);
+  rfc1524_mailcap_lookup(a, type, sizeof(type), entry, 0);
   mutt_rfc1524_expand_filename (entry->nametemplate, a->filename, tempfile);
 
   rfc1524_free_entry(&entry);
@@ -103,7 +103,7 @@ int mutt_compose_attachment (BODY *a)
   int rc = 0;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
-  if (rfc1524_mailcap_lookup (a, type, entry, MUTT_COMPOSE))
+  if (rfc1524_mailcap_lookup (a, type, sizeof(type), entry, MUTT_COMPOSE))
   {
     if (entry->composecommand || entry->composetypecommand)
     {
@@ -239,7 +239,7 @@ int mutt_edit_attachment (BODY *a)
   int rc = 0;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
-  if (rfc1524_mailcap_lookup (a, type, entry, MUTT_EDIT))
+  if (rfc1524_mailcap_lookup (a, type, sizeof(type), entry, MUTT_EDIT))
   {
     if (entry->editcommand)
     {
@@ -303,7 +303,7 @@ bailout:
 }
 
 
-void mutt_check_lookup_list (BODY *b, char *type, int len)
+void mutt_check_lookup_list (BODY *b, char *type, size_t len)
 {
   LIST *t = MimeLookupList;
   int i;
@@ -374,7 +374,7 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr,
   if (use_mailcap)
   {
     entry = rfc1524_new_entry ();
-    if (!rfc1524_mailcap_lookup (a, type, entry, 0))
+    if (!rfc1524_mailcap_lookup (a, type, sizeof(type), entry, 0))
     {
       if (flag == MUTT_REGULAR)
       {
@@ -929,7 +929,7 @@ int mutt_print_attachment (FILE *fp, BODY *a)
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
 
-  if (rfc1524_mailcap_lookup (a, type, NULL, MUTT_PRINT))
+  if (rfc1524_mailcap_lookup (a, type, sizeof(type), NULL, MUTT_PRINT))
   {
     rfc1524_entry *entry = NULL;
     int piped = FALSE;
@@ -937,7 +937,7 @@ int mutt_print_attachment (FILE *fp, BODY *a)
     dprint (2, (debugfile, "Using mailcap...\n"));
 
     entry = rfc1524_new_entry ();
-    rfc1524_mailcap_lookup (a, type, entry, MUTT_PRINT);
+    rfc1524_mailcap_lookup (a, type, sizeof(type), entry, MUTT_PRINT);
     mutt_rfc1524_expand_filename (entry->nametemplate, a->filename,
                                   newfile);
 
index 5a0766a8a36213d08b4b90a32fdd938c6ac11e9f..5e613d41de4174ec5dec0a5cbf1e0305e6aaca32 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -955,7 +955,7 @@ static int is_mmnoask (const char *buf)
  */
 static int mutt_is_autoview (BODY *b)
 {
-  char type[SHORT_STRING];
+  char type[STRING];
   int is_autoview = 0;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (b), b->subtype);
@@ -988,7 +988,7 @@ static int mutt_is_autoview (BODY *b)
    *
    * WARNING: type is altered by this call as a result of `mime_lookup' support */
   if (is_autoview)
-    return rfc1524_mailcap_lookup(b, type, NULL, MUTT_AUTOVIEW);
+    return rfc1524_mailcap_lookup(b, type, sizeof(type), NULL, MUTT_AUTOVIEW);
 
   return 0;
 }
@@ -1320,7 +1320,7 @@ static int autoview_handler (BODY *a, STATE *s)
   tempfile = mutt_buffer_pool_get ();
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
-  rfc1524_mailcap_lookup (a, type, entry, MUTT_AUTOVIEW);
+  rfc1524_mailcap_lookup (a, type, sizeof(type), entry, MUTT_AUTOVIEW);
 
   fname = safe_strdup (a->filename);
   mutt_sanitize_filename (fname, 1);
index 8ee932c8aca5e757f813c48868de8b8ce78e5992..759acc4f1d1fe746428a4e547ec936d3ce22edb7 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -236,7 +236,7 @@ const char *mutt_getcwd (BUFFER *);
 void mutt_help (int);
 const char *mutt_idxfmt_hook (const char *, CONTEXT *, HEADER *);
 void mutt_draw_tree (CONTEXT *);
-void mutt_check_lookup_list (BODY *, char *, int);
+void mutt_check_lookup_list (BODY *, char *, size_t);
 void mutt_make_attribution (CONTEXT *ctx, HEADER *cur, FILE *out);
 void mutt_make_forward_subject (ENVELOPE *env, CONTEXT *ctx, HEADER *cur);
 void mutt_make_help (char *, size_t, const char *, int, int);
index 087858c9560aebb299c083a3c748f259cf854767..c2da1785fd8ffcab57198b44370a57d0e801ef7a 100644 (file)
@@ -741,7 +741,7 @@ static int can_print (ATTACH_CONTEXT *actx, BODY *top, int tag)
     snprintf (type, sizeof (type), "%s/%s", TYPE (top), top->subtype);
     if (!tag || top->tagged)
     {
-      if (!rfc1524_mailcap_lookup (top, type, NULL, MUTT_PRINT))
+      if (!rfc1524_mailcap_lookup (top, type, sizeof(type), NULL, MUTT_PRINT))
       {
        if (ascii_strcasecmp ("text/plain", top->subtype) &&
            ascii_strcasecmp ("application/postscript", top->subtype))
@@ -775,7 +775,8 @@ static void print_attachment_list (ATTACH_CONTEXT *actx, FILE *fp, int tag, BODY
     if (!tag || top->tagged)
     {
       snprintf (type, sizeof (type), "%s/%s", TYPE (top), top->subtype);
-      if (!option (OPTATTACHSPLIT) && !rfc1524_mailcap_lookup (top, type, NULL, MUTT_PRINT))
+      if (!option (OPTATTACHSPLIT) &&
+          !rfc1524_mailcap_lookup (top, type, sizeof(type), NULL, MUTT_PRINT))
       {
        if (!ascii_strcasecmp ("text/plain", top->subtype) ||
            !ascii_strcasecmp ("application/postscript", top->subtype))
index 6597df2bb0bc7fbf947b24ba166f39dd707f9953..2fc9f17500961ed1a028a85278db81265996fa5a 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -420,7 +420,7 @@ void rfc1524_free_entry(rfc1524_entry **entry)
  * in *entry, and returns 1.  On failure (not found), returns 0.
  * If entry == NULL just return 1 if the given type is found.
  */
-int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
+int rfc1524_mailcap_lookup (BODY *a, char *type, size_t typelen, rfc1524_entry *entry, int opt)
 {
   BUFFER *path = NULL;
   int found = FALSE;
@@ -438,8 +438,7 @@ int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
     return 0;
   }
 
-  /* FIXME: sizeof type should be passed to rfc1524_mailcap_lookup() */
-  mutt_check_lookup_list (a, type, SHORT_STRING);
+  mutt_check_lookup_list (a, type, typelen);
 
   path = mutt_buffer_pool_get ();
 
index 87b06d6d0afb6b6484be8fb089efaff141805a02..bdf0468e7fe206f96e41e5533cde40abe2526831 100644 (file)
--- a/rfc1524.h
+++ b/rfc1524.h
@@ -38,7 +38,7 @@ rfc1524_entry *rfc1524_new_entry (void);
 void rfc1524_free_entry (rfc1524_entry **);
 int mutt_rfc1524_expand_command (BODY *, const char *, const char *, BUFFER *);
 void mutt_rfc1524_expand_filename (const char *, const char *, BUFFER *);
-int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int);
+int rfc1524_mailcap_lookup (BODY *, char *, size_t, rfc1524_entry *, int);
 int mutt_rename_file (const char *, const char *);
 
 #endif /* _RFC1524_H */