The MinGW.OSDN Windows System Libraries. Formerly designated as "MinGW.org Windows System Libraries", this encapsulates the "mingwrt" C runtime library extensions, and the "w32api" 32-bit MS-Windows API libraries.
Please note that this project no longer owns the "MinGW.org" domain name; any software which may be distributed from that domain is NOT supported by this project.
Revisión | 42731e38166ecd3d7f3e8e249638df25a51cf899 (tree) |
---|---|
Tiempo | 2020-03-11 08:02:32 |
Autor | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Correct defects in mbrtowc() invalid conversion state handling.
@@ -1,5 +1,14 @@ | ||
1 | 1 | 2020-03-10 Keith Marshall <keith@users.osdn.me> |
2 | 2 | |
3 | + Correct defects in mbrtowc() invalid conversion state handling. | |
4 | + | |
5 | + * mingwex/mbrconv.c (__mingw_mbrtowc_handler): Abort if restarting a | |
6 | + conversion when a low surrogate is pending, but has not been correctly | |
7 | + retrieved; additionally, reject any mbstate_t object content which is | |
8 | + already representative of a complete multibyte character sequence. | |
9 | + | |
10 | +2020-03-10 Keith Marshall <keith@users.osdn.me> | |
11 | + | |
3 | 12 | Base MBCS converter function call redirection on _ISOC99_SOURCE. |
4 | 13 | |
5 | 14 | * include/wchar.h (__mingw_redirect): New temporary macro; use it... |
@@ -91,20 +91,21 @@ size_t __mingw_mbrtowc_handler | ||
91 | 91 | if( pwc != NULL ) *pwc = state.wc[1]; |
92 | 92 | return (size_t)(0); |
93 | 93 | } |
94 | - /* FIXME: can we ever get a pending high surrogate without | |
95 | - * its accompanying low surrogate; if we can, should it be | |
96 | - * rejected as an invalid deferred conversion state? | |
97 | - */ | |
98 | - //else if( (state.mb[3] != '\0') && IS_HIGH_SURROGATE( state.wc[0] ) ) | |
99 | - // return errout( EINVAL, (size_t)(-1) ); | |
100 | - | |
101 | 94 | /* When the conversion state does not represent a deferred |
102 | - * surrogate pair, then restore it, and pass this through as | |
95 | + * low surrogate, then restore it, and pass this through as | |
103 | 96 | * an effective no-op. |
104 | 97 | */ |
105 | 98 | *ps = state.st; |
106 | 99 | return (size_t)(-2); |
107 | 100 | } |
101 | + /* In any context, other than the preceding (special) n == 0 | |
102 | + * case, for retrieval of a deferred low surrogate, a pending | |
103 | + * conversion state which represents a surrogate pair is not | |
104 | + * a valid state; reject it. | |
105 | + */ | |
106 | + if( IS_SURROGATE_PAIR( state.wc[0], state.wc[1] ) ) | |
107 | + return errout( EINVAL, (size_t)(-1) ); | |
108 | + | |
108 | 109 | /* Step over any pending MBCS bytes, which may already be |
109 | 110 | * present within the conversion state buffer, accumulating |
110 | 111 | * both the count of such pending bytes, together with a |
@@ -130,6 +131,12 @@ size_t __mingw_mbrtowc_handler | ||
130 | 131 | if( len < mbrlen_cur_max ) state.mb[len] = '\0'; |
131 | 132 | if( (int)(count = mbrlen_min( state.mb, len, retval.wc )) > 0 ) |
132 | 133 | { |
134 | + /* No valid conversion state should ever exist, where no | |
135 | + * additional bytes are required to complete a previously | |
136 | + * deferred multibyte character. | |
137 | + */ | |
138 | + if( pending >= count ) return errout( EILSEQ, (size_t)(-1) ); | |
139 | + | |
133 | 140 | /* The accumulated encoding state does now represent a |
134 | 141 | * complete MBCS sequence; when servicing an mbrtowc() call, |
135 | 142 | * with non-NULL return value pointer, we must store that |