1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-10 01:06:04 +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>
* 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
* $Revision: 1.5168 $
* $Revision: 1.5169 $
*****************************************************

View File

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

View File

@ -2492,7 +2492,11 @@ enum {
* Yes, I know that doesn't seem to make much sense.
* 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 */
#define GETKEYS_ECHO (GETKEY_BACKSLASH_C)
/* printf format string: \123 -> S, \0123 -> NL 3 */
#define GETKEYS_PRINTF_FMT (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C)
/* printf format string: \123 -> S, \0123 -> NL 3, \045 -> %% */
#define GETKEYS_PRINTF_FMT \
(GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C|GETKEY_PRINTF_PERCENT)
/* printf argument: \123 -> \123, \0123 -> S */
#define GETKEYS_PRINTF_ARG (GETKEY_BACKSLASH_C)
/* Full print without -e */

View File

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