|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74897 - in trunk: boost/regex/v4 libs/regex/src
From: john_at_[hidden]
Date: 2011-10-10 11:46:08
Author: johnmaddock
Date: 2011-10-10 11:46:07 EDT (Mon, 10 Oct 2011)
New Revision: 74897
URL: http://svn.boost.org/trac/boost/changeset/74897
Log:
Improve sprintf usage.
Stop passing UDT's through (...) even in meta programs.
Fixes #5958.
Refs #5835.
Text files modified:
trunk/boost/regex/v4/regex_format.hpp | 10 +++++++++-
trunk/libs/regex/src/cregex.cpp | 17 +++++++++++++++--
trunk/libs/regex/src/fileiter.cpp | 10 ++++++++--
trunk/libs/regex/src/posix_api.cpp | 10 ++++++++--
4 files changed, 40 insertions(+), 7 deletions(-)
Modified: trunk/boost/regex/v4/regex_format.hpp
==============================================================================
--- trunk/boost/regex/v4/regex_format.hpp (original)
+++ trunk/boost/regex/v4/regex_format.hpp 2011-10-10 11:46:07 EDT (Mon, 10 Oct 2011)
@@ -842,7 +842,15 @@
BOOST_MPL_HAS_XXX_TRAIT_DEF(const_iterator)
-struct any_type { any_type(...); };
+struct any_type
+{
+ template <class T>
+ any_type(const T&);
+ template <class T, class U>
+ any_type(const T&, const U&);
+ template <class T, class U, class V>
+ any_type(const T&, const U&, const V&);
+};
typedef char no_type;
typedef char (&unary_type)[2];
typedef char (&binary_type)[3];
Modified: trunk/libs/regex/src/cregex.cpp
==============================================================================
--- trunk/libs/regex/src/cregex.cpp (original)
+++ trunk/libs/regex/src/cregex.cpp 2011-10-10 11:46:07 EDT (Mon, 10 Oct 2011)
@@ -361,11 +361,24 @@
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;
}
Modified: trunk/libs/regex/src/fileiter.cpp
==============================================================================
--- trunk/libs/regex/src/fileiter.cpp (original)
+++ trunk/libs/regex/src/fileiter.cpp 2011-10-10 11:46:07 EDT (Mon, 10 Oct 2011)
@@ -847,10 +847,16 @@
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)
{
Modified: trunk/libs/regex/src/posix_api.cpp
==============================================================================
--- trunk/libs/regex/src/posix_api.cpp (original)
+++ trunk/libs/regex/src/posix_api.cpp 2011-10-10 11:46:07 EDT (Mon, 10 Oct 2011)
@@ -167,11 +167,17 @@
{
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;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk