• R/O
  • HTTP
  • SSH
  • HTTPS

mingw-org-wsl: Commit

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.


Commit MetaInfo

Revisión42731e38166ecd3d7f3e8e249638df25a51cf899 (tree)
Tiempo2020-03-11 08:02:32
AutorKeith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Correct defects in mbrtowc() invalid conversion state handling.

Cambiar Resumen

Diferencia incremental

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,5 +1,14 @@
11 2020-03-10 Keith Marshall <keith@users.osdn.me>
22
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+
312 Base MBCS converter function call redirection on _ISOC99_SOURCE.
413
514 * include/wchar.h (__mingw_redirect): New temporary macro; use it...
--- a/mingwrt/mingwex/mbrconv.c
+++ b/mingwrt/mingwex/mbrconv.c
@@ -91,20 +91,21 @@ size_t __mingw_mbrtowc_handler
9191 if( pwc != NULL ) *pwc = state.wc[1];
9292 return (size_t)(0);
9393 }
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-
10194 /* 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
10396 * an effective no-op.
10497 */
10598 *ps = state.st;
10699 return (size_t)(-2);
107100 }
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+
108109 /* Step over any pending MBCS bytes, which may already be
109110 * present within the conversion state buffer, accumulating
110111 * both the count of such pending bytes, together with a
@@ -130,6 +131,12 @@ size_t __mingw_mbrtowc_handler
130131 if( len < mbrlen_cur_max ) state.mb[len] = '\0';
131132 if( (int)(count = mbrlen_min( state.mb, len, retval.wc )) > 0 )
132133 {
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+
133140 /* The accumulated encoding state does now represent a
134141 * complete MBCS sequence; when servicing an mbrtowc() call,
135142 * with non-NULL return value pointer, we must store that
Show on old repository browser