1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-15 02:11:07 +02:00

28578: fix handling of numeric escapes that expand to "%" in printf

format strings, so they are not treated as format introducers.
This commit is contained in:
Bart Schaefer 2011-01-06 16:49:25 +00:00
parent dd0ad1ac23
commit 87d6527628
4 changed files with 19 additions and 8 deletions

View file

@ -1,3 +1,9 @@
2011-01-06 Barton E. Schaefer <schaefer@zsh.org>
* 28578 (plus test): Src/utils.c, Src/zsh.h, Test/B03print.ztst:
fix handling of numeric escapes that expand to "%" in printf
format strings, so they are not treated as format introducers.
2011-01-05 Peter Stephenson <p.w.stephenson@ntlworld.com> 2011-01-05 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 28568 c.f. 28549 (Ricky Zhou): Src/utils.c: buffer overflow * 28568 c.f. 28549 (Ricky Zhou): Src/utils.c: buffer overflow
@ -14043,5 +14049,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5168 $ * $Revision: 1.5169 $
***************************************************** *****************************************************

View file

@ -1,4 +1,3 @@
/* /*
* utils.c - miscellaneous utilities * utils.c - miscellaneous utilities
* *
@ -5523,6 +5522,8 @@ getkeystring(char *s, int *len, int how, int *misc)
} }
*t++ = zstrtol(s + (*s == 'x'), &s, *t++ = zstrtol(s + (*s == 'x'), &s,
(*s == 'x') ? 16 : 8); (*s == 'x') ? 16 : 8);
if ((how & GETKEY_PRINTF_PERCENT) && t[-1] == '%')
*t++ = '%';
if (svchar) { if (svchar) {
u[3] = svchar; u[3] = svchar;
svchar = '\0'; svchar = '\0';

View file

@ -2492,7 +2492,11 @@ enum {
* Yes, I know that doesn't seem to make much sense. * Yes, I know that doesn't seem to make much sense.
* It's for use in completion, comprenez? * It's for use in completion, comprenez?
*/ */
GETKEY_UPDATE_OFFSET = (1 << 7) GETKEY_UPDATE_OFFSET = (1 << 7),
/*
* When replacing numeric escapes for printf format strings, % -> %%
*/
GETKEY_PRINTF_PERCENT = (1 << 8)
}; };
/* /*
@ -2501,8 +2505,9 @@ enum {
*/ */
/* echo builtin */ /* echo builtin */
#define GETKEYS_ECHO (GETKEY_BACKSLASH_C) #define GETKEYS_ECHO (GETKEY_BACKSLASH_C)
/* printf format string: \123 -> S, \0123 -> NL 3 */ /* printf format string: \123 -> S, \0123 -> NL 3, \045 -> %% */
#define GETKEYS_PRINTF_FMT (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C) #define GETKEYS_PRINTF_FMT \
(GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C|GETKEY_PRINTF_PERCENT)
/* printf argument: \123 -> \123, \0123 -> S */ /* printf argument: \123 -> \123, \0123 -> S */
#define GETKEYS_PRINTF_ARG (GETKEY_BACKSLASH_C) #define GETKEYS_PRINTF_ARG (GETKEY_BACKSLASH_C)
/* Full print without -e */ /* Full print without -e */

View file

@ -105,10 +105,9 @@
0:numeric value of high numbered character 0:numeric value of high numbered character
>f0 >f0
# code will probably be changed to print the literal `%s' in this case
printf '\x25s\n' arg printf '\x25s\n' arg
0:using \x25 to introduce a format specifier 0:using \x25 to print a literal % in format
>arg >%s
printf '%3c\n' c printf '%3c\n' c
0:width specified in format specifier 0:width specified in format specifier