aboutsummaryrefslogtreecommitdiff
path: root/cutl/details/boost/regex/src
diff options
context:
space:
mode:
Diffstat (limited to 'cutl/details/boost/regex/src')
-rw-r--r--cutl/details/boost/regex/src/c_regex_traits.cxx21
-rw-r--r--cutl/details/boost/regex/src/cregex.cxx17
-rw-r--r--cutl/details/boost/regex/src/fileiter.cxx12
-rw-r--r--cutl/details/boost/regex/src/internals.hpp35
-rw-r--r--cutl/details/boost/regex/src/posix_api.cxx11
-rw-r--r--cutl/details/boost/regex/src/regex.cxx1
-rw-r--r--cutl/details/boost/regex/src/regex_raw_buffer.cxx4
-rw-r--r--cutl/details/boost/regex/src/w32_regex_traits.cxx12
-rw-r--r--cutl/details/boost/regex/src/wc_regex_traits.cxx21
-rw-r--r--cutl/details/boost/regex/src/wide_posix_api.cxx16
10 files changed, 90 insertions, 60 deletions
diff --git a/cutl/details/boost/regex/src/c_regex_traits.cxx b/cutl/details/boost/regex/src/c_regex_traits.cxx
index b0f3a47..126e95c 100644
--- a/cutl/details/boost/regex/src/c_regex_traits.cxx
+++ b/cutl/details/boost/regex/src/c_regex_traits.cxx
@@ -21,6 +21,7 @@
#include <cutl/details/boost/config.hpp>
#include <cutl/details/boost/detail/workaround.hpp>
+#include "internals.hpp"
#if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
@@ -107,26 +108,6 @@ c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::transfo
return result;
}
-enum
-{
- char_class_space=1<<0,
- char_class_print=1<<1,
- char_class_cntrl=1<<2,
- char_class_upper=1<<3,
- char_class_lower=1<<4,
- char_class_alpha=1<<5,
- char_class_digit=1<<6,
- char_class_punct=1<<7,
- char_class_xdigit=1<<8,
- char_class_alnum=char_class_alpha|char_class_digit,
- char_class_graph=char_class_alnum|char_class_punct,
- char_class_blank=1<<9,
- char_class_word=1<<10,
- char_class_unicode=1<<11,
- char_class_horizontal=1<<12,
- char_class_vertical=1<<13
-};
-
c_regex_traits<char>::char_class_type BOOST_REGEX_CALL c_regex_traits<char>::lookup_classname(const char* p1, const char* p2)
{
static const char_class_type masks[] =
diff --git a/cutl/details/boost/regex/src/cregex.cxx b/cutl/details/boost/regex/src/cregex.cxx
index cf8154f..c64f993 100644
--- a/cutl/details/boost/regex/src/cregex.cxx
+++ b/cutl/details/boost/regex/src/cregex.cxx
@@ -361,11 +361,24 @@ void BuildFileList(std::list<std::string>* pl, const char* files, bool recurse)
while(dstart != dend)
{
+ // Verify that sprintf will not overflow:
+ if(std::strlen(dstart.path()) + std::strlen(directory_iterator::separator()) + std::strlen(ptr) >= MAX_PATH)
+ {
+ // Oops overflow, skip this item:
+ ++dstart;
+ continue;
+ }
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
- (::sprintf_s)(buf, sizeof(buf), "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
+ int r = (::sprintf_s)(buf, sizeof(buf), "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
#else
- (std::sprintf)(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
+ int r = (std::sprintf)(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
#endif
+ if(r < 0)
+ {
+ // sprintf failed, skip this item:
+ ++dstart;
+ continue;
+ }
BuildFileList(pl, buf, recurse);
++dstart;
}
diff --git a/cutl/details/boost/regex/src/fileiter.cxx b/cutl/details/boost/regex/src/fileiter.cxx
index 0a669a8..9a99222 100644
--- a/cutl/details/boost/regex/src/fileiter.cxx
+++ b/cutl/details/boost/regex/src/fileiter.cxx
@@ -19,6 +19,7 @@
#define BOOST_REGEX_SOURCE
+#include <cutl/details/boost/config.hpp>
#include <climits>
#include <stdexcept>
#include <string>
@@ -847,10 +848,16 @@ bool iswild(const char* mask, const char* name)
unsigned _fi_attributes(const char* root, const char* name)
{
char buf[MAX_PATH];
+ // verify that we can not overflow:
+ if(std::strlen(root) + std::strlen(_fi_sep) + std::strlen(name) >= MAX_PATH)
+ return 0;
+ int r;
if( ( (root[0] == *_fi_sep) || (root[0] == *_fi_sep_alt) ) && (root[1] == '\0') )
- (std::sprintf)(buf, "%s%s", root, name);
+ r = (std::sprintf)(buf, "%s%s", root, name);
else
- (std::sprintf)(buf, "%s%s%s", root, _fi_sep, name);
+ r = (std::sprintf)(buf, "%s%s%s", root, _fi_sep, name);
+ if(r < 0)
+ return 0; // sprintf failed
DIR* d = opendir(buf);
if(d)
{
@@ -870,6 +877,7 @@ _fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindF
{
if(_fi_FindNextFile(dat, lpFindFileData))
return dat;
+ closedir(h);
}
delete dat;
return 0;
diff --git a/cutl/details/boost/regex/src/internals.hpp b/cutl/details/boost/regex/src/internals.hpp
new file mode 100644
index 0000000..3a15cc6
--- /dev/null
+++ b/cutl/details/boost/regex/src/internals.hpp
@@ -0,0 +1,35 @@
+/*
+ *
+ * Copyright (c) 2011
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#ifndef BOOST_REGEX_SRC_INTERNALS_HPP
+#define BOOST_REGEX_SRC_INTERNALS_HPP
+
+enum
+{
+ char_class_space=1<<0,
+ char_class_print=1<<1,
+ char_class_cntrl=1<<2,
+ char_class_upper=1<<3,
+ char_class_lower=1<<4,
+ char_class_alpha=1<<5,
+ char_class_digit=1<<6,
+ char_class_punct=1<<7,
+ char_class_xdigit=1<<8,
+ char_class_alnum=char_class_alpha|char_class_digit,
+ char_class_graph=char_class_alnum|char_class_punct,
+ char_class_blank=1<<9,
+ char_class_word=1<<10,
+ char_class_unicode=1<<11,
+ char_class_horizontal=1<<12,
+ char_class_vertical=1<<13
+};
+
+#endif // BOOST_REGEX_SRC_INTERNALS_HPP
diff --git a/cutl/details/boost/regex/src/posix_api.cxx b/cutl/details/boost/regex/src/posix_api.cxx
index 589a235..02d76bf 100644
--- a/cutl/details/boost/regex/src/posix_api.cxx
+++ b/cutl/details/boost/regex/src/posix_api.cxx
@@ -18,6 +18,7 @@
#define BOOST_REGEX_SOURCE
+#include <cutl/details/boost/config.hpp>
#include <cstdio>
#include <cutl/details/boost/regex.hpp>
#include <cutl/details/boost/cregex.hpp>
@@ -167,11 +168,17 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int code, const regex_tA*
{
if(std::strcmp(e->re_endp, names[i]) == 0)
{
+ //
+ // We're converting an integer i to a string, and since i <= REG_E_UNKNOWN
+ // a five character string is *always* large enough:
+ //
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(_WIN32_WCE) && !defined(UNDER_CE)
- (::sprintf_s)(localbuf, 5, "%d", i);
+ int r = (::sprintf_s)(localbuf, 5, "%d", i);
#else
- (std::sprintf)(localbuf, "%d", i);
+ int r = (std::sprintf)(localbuf, "%d", i);
#endif
+ if(r < 0)
+ return 0; // sprintf failed
if(std::strlen(localbuf) < buf_size)
re_detail::strcpy_s(buf, buf_size, localbuf);
return std::strlen(localbuf) + 1;
diff --git a/cutl/details/boost/regex/src/regex.cxx b/cutl/details/boost/regex/src/regex.cxx
index 0f3938e..28f40d0 100644
--- a/cutl/details/boost/regex/src/regex.cxx
+++ b/cutl/details/boost/regex/src/regex.cxx
@@ -19,6 +19,7 @@
#define BOOST_REGEX_SOURCE
+#include <cutl/details/boost/config.hpp>
#include <new>
#include <cutl/details/boost/regex.hpp>
#include <cutl/details/boost/throw_exception.hpp>
diff --git a/cutl/details/boost/regex/src/regex_raw_buffer.cxx b/cutl/details/boost/regex/src/regex_raw_buffer.cxx
index a0c4811..7b06725 100644
--- a/cutl/details/boost/regex/src/regex_raw_buffer.cxx
+++ b/cutl/details/boost/regex/src/regex_raw_buffer.cxx
@@ -18,6 +18,7 @@
#define BOOST_REGEX_SOURCE
+#include <cutl/details/boost/config.hpp>
#include <memory>
#include <cstring>
#include <cutl/details/boost/assert.hpp>
@@ -45,7 +46,8 @@ void BOOST_REGEX_CALL raw_storage::resize(size_type n)
// allocate and copy data:
register pointer ptr = static_cast<pointer>(::operator new(newsize));
BOOST_REGEX_NOEH_ASSERT(ptr)
- std::memcpy(ptr, start, datasize);
+ if(start)
+ std::memcpy(ptr, start, datasize);
// get rid of old buffer:
::operator delete(start);
diff --git a/cutl/details/boost/regex/src/w32_regex_traits.cxx b/cutl/details/boost/regex/src/w32_regex_traits.cxx
index d17db73..c9d29e8 100644
--- a/cutl/details/boost/regex/src/w32_regex_traits.cxx
+++ b/cutl/details/boost/regex/src/w32_regex_traits.cxx
@@ -283,9 +283,11 @@ BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, l
if (r == 0)
return def;
- LPSTR buf = (LPSTR)_alloca( (r + 1) * 2 );
- if (::WideCharToMultiByte(CP_ACP, 0, wbuf, r, buf, (r + 1) * 2, NULL, NULL) == 0)
- return def;
+
+ int buf_size = 1 + ::WideCharToMultiByte(CP_ACP, 0, wbuf, r, NULL, 0, NULL, NULL);
+ LPSTR buf = (LPSTR)_alloca(buf_size);
+ if (::WideCharToMultiByte(CP_ACP, 0, wbuf, r, buf, buf_size, NULL, NULL) == 0)
+ return def; // failed conversion.
#endif
return std::string(buf);
}
@@ -485,7 +487,7 @@ BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type idx)
return c;
if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0)
- return c;
+ return c; // No single byte lower case equivalent available
#endif
return result[0];
}
@@ -556,7 +558,7 @@ BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type idx)
return c;
if (::WideCharToMultiByte(code_page, 0, &wide_result, 1, result, 2, NULL, NULL) == 0)
- return c;
+ return c; // No single byte upper case equivalent available.
#endif
return result[0];
}
diff --git a/cutl/details/boost/regex/src/wc_regex_traits.cxx b/cutl/details/boost/regex/src/wc_regex_traits.cxx
index 2c6b44b..29d3bd1 100644
--- a/cutl/details/boost/regex/src/wc_regex_traits.cxx
+++ b/cutl/details/boost/regex/src/wc_regex_traits.cxx
@@ -22,6 +22,7 @@
#include <cutl/details/boost/detail/workaround.hpp>
#include <memory>
#include <string>
+#include "internals.hpp"
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \
&& !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\
@@ -147,26 +148,6 @@ c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::t
return result;
}
-enum
-{
- char_class_space=1<<0,
- char_class_print=1<<1,
- char_class_cntrl=1<<2,
- char_class_upper=1<<3,
- char_class_lower=1<<4,
- char_class_alpha=1<<5,
- char_class_digit=1<<6,
- char_class_punct=1<<7,
- char_class_xdigit=1<<8,
- char_class_alnum=char_class_alpha|char_class_digit,
- char_class_graph=char_class_alnum|char_class_punct,
- char_class_blank=1<<9,
- char_class_word=1<<10,
- char_class_unicode=1<<11,
- char_class_horizontal=1<<12,
- char_class_vertical=1<<13
-};
-
c_regex_traits<wchar_t>::char_class_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::lookup_classname(const wchar_t* p1, const wchar_t* p2)
{
static const char_class_type masks[] =
diff --git a/cutl/details/boost/regex/src/wide_posix_api.cxx b/cutl/details/boost/regex/src/wide_posix_api.cxx
index d132480..6c42679 100644
--- a/cutl/details/boost/regex/src/wide_posix_api.cxx
+++ b/cutl/details/boost/regex/src/wide_posix_api.cxx
@@ -74,7 +74,7 @@ const wchar_t* wnames[] = {
};
}
-typedef cutl_details_boost::basic_regex<wchar_t, c_regex_traits<wchar_t> > c_regex_type;
+typedef cutl_details_boost::basic_regex<wchar_t, c_regex_traits<wchar_t> > wc_regex_type;
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wchar_t* ptr, int f)
{
@@ -84,7 +84,7 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
- expression->guts = new c_regex_type();
+ expression->guts = new wc_regex_type();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
@@ -134,9 +134,9 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha
try{
#endif
expression->re_magic = wmagic_value;
- static_cast<c_regex_type*>(expression->guts)->set_expression(ptr, p2, flags);
- expression->re_nsub = static_cast<c_regex_type*>(expression->guts)->mark_count() - 1;
- result = static_cast<c_regex_type*>(expression->guts)->error_code();
+ static_cast<wc_regex_type*>(expression->guts)->set_expression(ptr, p2, flags);
+ expression->re_nsub = static_cast<wc_regex_type*>(expression->guts)->mark_count() - 1;
+ result = static_cast<wc_regex_type*>(expression->guts)->error_code();
#ifndef BOOST_NO_EXCEPTIONS
}
catch(const cutl_details_boost::regex_error& be)
@@ -215,7 +215,7 @@ BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int code, const regex_tW*
{
std::string p;
if((e) && (e->re_magic == wmagic_value))
- p = static_cast<c_regex_type*>(e->guts)->get_traits().error_string(static_cast< ::cutl_details_boost::regex_constants::error_type>(code));
+ p = static_cast<wc_regex_type*>(e->guts)->get_traits().error_string(static_cast< ::cutl_details_boost::regex_constants::error_type>(code));
else
{
p = re_detail::get_default_error_string(static_cast< ::cutl_details_boost::regex_constants::error_type>(code));
@@ -264,7 +264,7 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW* expression, cons
#endif
if(expression->re_magic == wmagic_value)
{
- result = regex_search(start, end, m, *static_cast<c_regex_type*>(expression->guts), flags);
+ result = regex_search(start, end, m, *static_cast<wc_regex_type*>(expression->guts), flags);
}
else
return result;
@@ -301,7 +301,7 @@ BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW* expression)
{
if(expression->re_magic == wmagic_value)
{
- delete static_cast<c_regex_type*>(expression->guts);
+ delete static_cast<wc_regex_type*>(expression->guts);
}
expression->re_magic = 0;
}