hi there -

i noticed an oversight in the comsat code.  when
expand_line/expand_escape inserted the value of any header or body
line with double quotes in it, mu_argcv_get would then misinterpret
the string tokenisation.  for instance, if parsing a %H{From} when the
>From header contains `"My Name" <[EMAIL PROTECTED]>', we have:

1. echo "%H{From}"

-> 2. echo ""My Name" <[EMAIL PROTECTED]>"

-> 3. echo, My, Name <[EMAIL PROTECTED]>

then action_echo just echoes argv[1] which is `My'; i.e. the action is
truncated unexpectedly.

the attached patch fixes this by calling mu_argcv_get FIRST, then
parsing each argv with expand_line to catch the escape sequences.

i also noticed that mu_argcv_free was only called in run_user_action
when there was an error parsing the arguments; otherwise each action's
argv strings stay in memory.  this is not a big deal since the program
exits after running the action, but on the other hand it doesn't
really look good either, so the patch also makes sure to call
mu_argcv_free wherever appropriate.

hope this helps!

-damon
--- mailutils-1.0.orig/comsat/action.c  2005-08-29 03:21:54.000000000 -0700
+++ mailutils-1.0/comsat/action.c       2006-08-25 15:14:14.000000000 -0700
@@ -345,23 +345,33 @@
 
       while (act_getline (fp, &stmt, &size))
        {
-         char *str;
          int argc;
          char **argv;
+          int c;
 
          line++;
-         str = expand_line (stmt, msg);
-         if (!str)
-           continue;
-         if (mu_argcv_get (str, "", NULL, &argc, &argv)
+         if (mu_argcv_get (stmt, "", NULL, &argc, &argv)
              || argc == 0
              || argv[0][0] == '#')
            {
-             free (str);
              mu_argcv_free (argc, argv);
              continue;
            }
 
+          for(c=1; c<argc; c++)
+            {
+              char *oldarg = argv[c];
+              argv[c] = expand_line (argv[c], msg);
+              free(oldarg);
+              if (!argv[c])
+                break;
+            }
+          if (c < argc) /* loop did not complete due to failed expand_line */
+            {
+              mu_argcv_free (argc, argv);
+              continue;
+            }
+
          if (strcmp (argv[0], "beep") == 0)
            {
              action_beep (tty);
@@ -383,8 +393,10 @@
              fprintf (tty, "\r\n");
              syslog (LOG_ERR, _("%s:.biffrc:%d: unknown keyword %s"),
                      username, line, argv[0]);
+              mu_argcv_free (argc, argv);
              break;
            }
+          mu_argcv_free (argc, argv);
        }
       fclose (fp);
     }
_______________________________________________
Bug-mailutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-mailutils

Reply via email to