diff options
author | Keith Marshall <keithmarshall@@users.sf.net> | 2008-12-31 18:34:09 +0300 |
---|---|---|
committer | Keith Marshall <keithmarshall@@users.sf.net> | 2008-12-31 18:34:09 +0300 |
commit | 762cf3ee22b047d7eb0a06bf05a16dffab54cc53 (patch) | |
tree | a42f395e32b3bff70f52bb72a6d16057b4674f40 /winsup/mingw/mingwex | |
parent | 0c94c057a4ffa47915e3864f258dc4a8f760e1e2 (diff) |
Correct mishandling of invalid characters in printf() format specs.
Diffstat (limited to 'winsup/mingw/mingwex')
-rw-r--r-- | winsup/mingw/mingwex/stdio/pformat.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/winsup/mingw/mingwex/stdio/pformat.c b/winsup/mingw/mingwex/stdio/pformat.c index 8b3e93ed4..2151a0945 100644 --- a/winsup/mingw/mingwex/stdio/pformat.c +++ b/winsup/mingw/mingwex/stdio/pformat.c @@ -1813,6 +1813,11 @@ int __pformat( int flags, void *dest, int max, const char *fmt, va_list argv ) __pformat_state_t state = PFORMAT_INIT; __pformat_length_t length = PFORMAT_LENGTH_INT; + /* Save the current format scan position, so that we can backtrack + * in the event of encountering an invalid format specification... + */ + char *backtrack = fmt; + /* Restart capture for dynamic field width and precision specs... */ int *width_spec = &stream.width; @@ -2490,12 +2495,15 @@ int __pformat( int flags, void *dest, int max, const char *fmt, va_list argv ) } else + { /* We found a digit out of context, or some other character - * with no designated meaning; silently reject it, and any - * further characters other than argument length modifiers, - * until this format specification is completely resolved. + * with no designated meaning; reject this format specification, + * backtrack, and emit it as literal text... */ - state = PFORMAT_END; + fmt = backtrack; + __pformat_putc( '%', &stream ); + goto format_scan; + } } } } |