[libcxx-commits] [PATCH] D69553: [libcxx] Error out if __libcpp_mbsrtowcs_l fails to convert anything in __time_get_storage

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 29 02:41:35 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: EricWF, ldionne, mclow.lists.
Herald added subscribers: dexonsmith, christof.

If `__libcpp_mbsrtowcs_l` outputs zero wchar_t's for week days or month names (due to errors in the locale function setup), these are matched all the time in `__time_get_storage::__analyze`, ending up in an infinite loop, allocating more memory until killed.


Repository:
  rCXX libc++

https://reviews.llvm.org/D69553

Files:
  libcxx/src/locale.cpp


Index: libcxx/src/locale.cpp
===================================================================
--- libcxx/src/locale.cpp
+++ libcxx/src/locale.cpp
@@ -5128,7 +5128,7 @@
         mb = mbstate_t();
         const char* bb = buf;
         size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
-        if (j == size_t(-1))
+        if (j == size_t(-1) || j == 0)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __weeks_[i].assign(wbuf, wbe);
@@ -5136,7 +5136,7 @@
         mb = mbstate_t();
         bb = buf;
         j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
-        if (j == size_t(-1))
+        if (j == size_t(-1) || j == 0)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __weeks_[i+7].assign(wbuf, wbe);
@@ -5149,7 +5149,7 @@
         mb = mbstate_t();
         const char* bb = buf;
         size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
-        if (j == size_t(-1))
+        if (j == size_t(-1) || j == 0)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __months_[i].assign(wbuf, wbe);
@@ -5157,7 +5157,7 @@
         mb = mbstate_t();
         bb = buf;
         j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
-        if (j == size_t(-1))
+        if (j == size_t(-1) || j == 0)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
         __months_[i+12].assign(wbuf, wbe);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69553.226856.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191029/09274c95/attachment-0001.bin>


More information about the libcxx-commits mailing list