Print this page
5366 strcoll_l may destroy its arguments, then crash

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/mbstowcs.c
          +++ new/usr/src/lib/libc/port/locale/mbstowcs.c
↓ open down ↓ 31 lines elided ↑ open up ↑
  32   32  #include <wchar.h>
  33   33  #include <locale.h>
  34   34  #include "mblocal.h"
  35   35  #include "localeimpl.h"
  36   36  #include "lctype.h"
  37   37  
  38   38  size_t
  39   39  mbstowcs_l(wchar_t *_RESTRICT_KYWD pwcs, const char *_RESTRICT_KYWD s,
  40   40      size_t n, locale_t loc)
  41   41  {
  42      -        static const mbstate_t initial = { 0 };
  43      -        mbstate_t mbs;
       42 +        mbstate_t mbs = { 0 };
  44   43          const char *sp;
  45   44  
  46      -        mbs = initial;
  47   45          sp = s;
  48   46          return (loc->ctype->lc_mbsnrtowcs(pwcs, &sp, ULONG_MAX, n, &mbs));
  49   47  }
  50   48  
  51   49  size_t
  52   50  mbstowcs(wchar_t *_RESTRICT_KYWD pwcs, const char *_RESTRICT_KYWD s, size_t n)
  53   51  {
  54   52          return (mbstowcs_l(pwcs, s, n, uselocale(NULL)));
  55   53  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX