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/strcoll.c
          +++ new/usr/src/lib/libc/port/locale/strcoll.c
↓ open down ↓ 47 lines elided ↑ open up ↑
  48   48   */
  49   49  int
  50   50  strcoll_l(const char *s1, const char *s2, locale_t loc)
  51   51  {
  52   52          int ret;
  53   53          wchar_t *t1 = NULL, *t2 = NULL;
  54   54          wchar_t *w1 = NULL, *w2 = NULL;
  55   55          size_t sz1, sz2;
  56   56          const struct lc_collate *lcc = loc->collate;
  57   57  
  58      -        mbstate_t mbs1 = { 0 }; /* initial states */
  59      -        mbstate_t mbs2 = { 0 };
  60      -
  61   58          if (lcc->lc_is_posix)
  62   59                  return (strcmp(s1, s2));
  63   60  
  64   61          sz1 = strlen(s1) + 1;
  65   62          sz2 = strlen(s2) + 1;
  66   63  
  67   64          /*
  68   65           * Simple assumption: conversion to wide format is strictly
  69   66           * reducing, i.e. a single byte (or multibyte character)
  70   67           * cannot result in multiple wide characters.
↓ open down ↓ 11 lines elided ↑ open up ↑
  82   79          }
  83   80          if (sz2 > ALLOCA_LIMIT) {
  84   81                  if ((t2 = malloc(sz2 * sizeof (wchar_t))) == NULL)
  85   82                          goto error;
  86   83                  w2 = t2;
  87   84          } else {
  88   85                  if ((w2 = alloca(sz2 * sizeof (wchar_t))) == NULL)
  89   86                          goto error;
  90   87          }
  91   88  
  92      -        if ((mbsrtowcs_l(w1, &s1, sz1, &mbs1, loc)) == (size_t)-1)
       89 +        if ((mbstowcs_l(w1, s1, sz1, loc)) == (size_t)-1)
  93   90                  goto error;
  94   91  
  95      -        if ((mbsrtowcs_l(w2, &s2, sz2, &mbs2, loc)) == (size_t)-1)
       92 +        if ((mbstowcs_l(w2, s2, sz2, loc)) == (size_t)-1)
  96   93                  goto error;
  97   94  
  98   95          ret = wcscoll_l(w1, w2, loc);
  99   96          if (t1)
 100   97                  free(t1);
 101   98          if (t2)
 102   99                  free(t2);
 103  100  
 104  101          return (ret);
 105  102  
↓ open down ↓ 13 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX