2010-01-19 Andy Koppe <andy.koppe@gmail.com>
* libc/stdio/vfscanf.c (__SVFSCANF_R): Fix handling of non-ASCII characters and allow invalid bytes in format string.
This commit is contained in:
parent
8c72ebb7e0
commit
044cd63533
|
@ -1,3 +1,8 @@
|
||||||
|
2010-01-19 Andy Koppe <andy.koppe@gmail.com>
|
||||||
|
|
||||||
|
* libc/stdio/vfscanf.c (__SVFSCANF_R): Fix handling of non-ASCII
|
||||||
|
characters and allow invalid bytes in format string.
|
||||||
|
|
||||||
2010-01-19 Corinna Vinschen <corinna@vinschen.de>
|
2010-01-19 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* libc/stdlib/wcstombs_r.c (_wcstombs_r): Handle invalid characters
|
* libc/stdlib/wcstombs_r.c (_wcstombs_r): Handle invalid characters
|
||||||
|
|
|
@ -459,7 +459,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
u_long (*ccfn)CCFN_PARAMS=0; /* conversion function (strtol/strtoul) */
|
u_long (*ccfn)CCFN_PARAMS=0; /* conversion function (strtol/strtoul) */
|
||||||
char ccltab[256]; /* character class table for %[...] */
|
char ccltab[256]; /* character class table for %[...] */
|
||||||
char buf[BUF]; /* buffer for numeric conversions */
|
char buf[BUF]; /* buffer for numeric conversions */
|
||||||
char *lptr; /* literal pointer */
|
unsigned char *lptr; /* literal pointer */
|
||||||
|
|
||||||
char *cp;
|
char *cp;
|
||||||
short *sp;
|
short *sp;
|
||||||
|
@ -501,16 +501,25 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
|
|
||||||
nassigned = 0;
|
nassigned = 0;
|
||||||
nread = 0;
|
nread = 0;
|
||||||
|
#ifdef _MB_CAPABLE
|
||||||
|
memset (&state, 0, sizeof (state));
|
||||||
|
#endif
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
#ifndef _MB_CAPABLE
|
#ifndef _MB_CAPABLE
|
||||||
wc = *fmt;
|
wc = *fmt;
|
||||||
#else
|
#else
|
||||||
memset (&state, '\0', sizeof (state));
|
|
||||||
nbytes = __mbtowc (rptr, &wc, fmt, MB_CUR_MAX, __locale_charset (),
|
nbytes = __mbtowc (rptr, &wc, fmt, MB_CUR_MAX, __locale_charset (),
|
||||||
&state);
|
&state);
|
||||||
|
if (nbytes < 0) {
|
||||||
|
wc = 0xFFFD; /* Unicode replacement character */
|
||||||
|
nbytes = 1;
|
||||||
|
memset (&state, 0, sizeof (state));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
fmt += nbytes;
|
fmt += nbytes;
|
||||||
|
|
||||||
if (wc == 0)
|
if (wc == 0)
|
||||||
goto all_done;
|
goto all_done;
|
||||||
if (nbytes == 1 && isspace (wc))
|
if (nbytes == 1 && isspace (wc))
|
||||||
|
@ -839,6 +848,8 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
|
#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 2
|
||||||
if (flags & LONG)
|
if (flags & LONG)
|
||||||
{
|
{
|
||||||
|
mbstate_t state;
|
||||||
|
memset (&state, 0, sizeof (mbstate_t));
|
||||||
if ((flags & SUPPRESS) == 0)
|
if ((flags & SUPPRESS) == 0)
|
||||||
wcp = GET_ARG (N, ap, wchar_t *);
|
wcp = GET_ARG (N, ap, wchar_t *);
|
||||||
else
|
else
|
||||||
|
@ -851,7 +862,6 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
buf[n++] = *fp->_p;
|
buf[n++] = *fp->_p;
|
||||||
fp->_r -= 1;
|
fp->_r -= 1;
|
||||||
fp->_p += 1;
|
fp->_p += 1;
|
||||||
memset ((_PTR)&state, '\0', sizeof (mbstate_t));
|
|
||||||
if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
|
if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
|
||||||
== (size_t)-1)
|
== (size_t)-1)
|
||||||
goto input_failure; /* Invalid sequence */
|
goto input_failure; /* Invalid sequence */
|
||||||
|
@ -971,6 +981,8 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
if (flags & LONG)
|
if (flags & LONG)
|
||||||
{
|
{
|
||||||
/* Process %S and %ls placeholders */
|
/* Process %S and %ls placeholders */
|
||||||
|
mbstate_t state;
|
||||||
|
memset (&state, 0, sizeof (mbstate_t));
|
||||||
if ((flags & SUPPRESS) == 0)
|
if ((flags & SUPPRESS) == 0)
|
||||||
wcp = GET_ARG (N, ap, wchar_t *);
|
wcp = GET_ARG (N, ap, wchar_t *);
|
||||||
else
|
else
|
||||||
|
@ -983,7 +995,6 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
|
||||||
buf[n++] = *fp->_p;
|
buf[n++] = *fp->_p;
|
||||||
fp->_r -= 1;
|
fp->_r -= 1;
|
||||||
fp->_p += 1;
|
fp->_p += 1;
|
||||||
memset ((_PTR)&state, '\0', sizeof (mbstate_t));
|
|
||||||
if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
|
if ((mbslen = _mbrtowc_r (rptr, wcp, buf, n, &state))
|
||||||
== (size_t)-1)
|
== (size_t)-1)
|
||||||
goto input_failure;
|
goto input_failure;
|
||||||
|
|
Loading…
Reference in New Issue