----- Forwarded message from Fumitoshi UKAI <[EMAIL PROTECTED]> -----

Subject: Bug#53221: info does not care position parameter in format string
Reply-To: Fumitoshi UKAI <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
X-Debian-PR-Message: report 53221
X-Debian-PR-Package: info
Date: Wed, 22 Dec 1999 01:17:51 +0900
From: Fumitoshi UKAI <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
User-Agent: Wanderlust/2.2.12 (Joyride) SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) 
Emacs/20.4 (i386-debian-linux-gnu) MULE/4.0 (HANANOEN)
Organization: Debian JP Project

Package: info
Version: 4.0-2

In window.c, build_message_buffer() format strings, but it doesn't 
care position parameter in format string like `%1$s'.  This kind of
position parameter is necessary for translated messages.
At least, /usr/share/locales/ja/LC_MESSAGES/texinfo.mo (in ja-trans
package) cause segmentation fault when we invoke info againt unknown node
like:

 % info hogehoge

This evil patch fixes this problem, but I think it's better to
use asprintf(3) or something like that.

--- window.c~   Sat Jun 26 06:57:40 1999
+++ window.c    Wed Dec 22 01:10:25 1999
@@ -1326,7 +1326,9 @@
           char *fmt_start = format + i;
           char *fmt;
           int fmt_len, formatted_len;
+         int paramed = 0;
 
+       format_again:
           i++;
           while (format[i] && strchr ("-. +0123456789", format[i]))
             i++;
@@ -1335,18 +1337,38 @@
           if (c == '\0')
             abort ();
 
+         if (c == '$') {
+           /* position parameter parameter */
+           arg_index = atoi(fmt_start + 1) - 1;
+           if (arg_index < 0)
+             arg_index = 0;
+           if (arg_index >= 2)
+             arg_index = 1;
+           paramed = 1;
+           goto format_again;
+         }
+
           fmt_len = format + i - fmt_start + 1;
           fmt = (char *) xmalloc (fmt_len + 1);
           strncpy (fmt, fmt_start, fmt_len);
           fmt[fmt_len] = '\0';
 
+         if (paramed) {
+           /* removed positioned parameter */
+           char *p;
+           for (p = fmt + 1; *p && *p != '$'; p++) {
+             ;
+           }
+           strcpy(fmt + 1, p + 1);
+         }
+
           /* If we have "%-98s", maybe 98 calls for a longer string.  */
           if (fmt_len > 2)
             {
               int j;
 
-              for (j = 0; j < fmt_len; j++)
-                if (isdigit (fmt[j]))
+              for (j = fmt_len - 2; j >= 0; j--)
+                if (isdigit (fmt[j]) || fmt[j] == '$')
                   break;
 
               formatted_len = atoi (fmt + j);


Thanks,
Fumitoshi UKAI

----- End forwarded message -----

-- 
enJoy -*/\*- don't even try to pronounce my first name

Reply via email to