This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] Fix to time_get for end deref
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 09 Nov 2004 13:47:20 +0100
- Subject: [v3] Fix to time_get for end deref
Hi,
noticed a couple of remaining places (most already fixed for 3.4)
where we risked dereferencing end iterators.
Tested x86-linux, committing to mainline (soon 3_4 too).
Paolo.
P.S. Later, we can consider reorganizing a bit where in the time_get
helpers we set __err |= ios_base::eofbit / check for it...
//////////////
2004-11-09 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (time_get<>::do_get_weekday,
time_get<>::do_get_monthname): Absolutely avoid dereferencing
the end iterator.
* include/bits/locale_facets.tcc (time_get<>::_M_extract_name):
Minor tweak.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc 2004-11-04 12:29:30.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc 2004-11-09 12:58:46.000000000 +0100
@@ -2043,8 +2043,7 @@
for (size_t __i2 = 1; __i2 < __nmatches; ++__i2)
__minlen = std::min(__minlen,
__traits_type::length(__names[__matches[__i2]]));
- ++__pos;
- ++__beg;
+ ++__beg, ++__pos;
if (__pos < __minlen && __beg != __end)
for (size_t __i3 = 0; __i3 < __nmatches;)
{
@@ -2061,8 +2060,7 @@
if (__nmatches == 1)
{
// Make sure found name is completely extracted.
- ++__pos;
- ++__beg;
+ ++__beg, ++__pos;
__name = __names[__matches[0]];
const size_t __len = __traits_type::length(__name);
while (__pos < __len && __beg != __end && __name[__pos] == *__beg)
@@ -2135,7 +2133,7 @@
// __days array with the same index points to a day, and that
// day's abbreviated form.
// NB: Also assumes that an abbreviated name is a subset of the name.
- if (!__err)
+ if (!__err && __beg != __end)
{
size_t __pos = __traits_type::length(__days[__tmpwday]);
__tp._M_days(__days);
@@ -2150,9 +2148,10 @@
if (__len != __pos)
__err |= ios_base::failbit;
}
- if (!__err)
- __tm->tm_wday = __tmpwday;
}
+ if (!__err)
+ __tm->tm_wday = __tmpwday;
+
if (__beg == __end)
__err |= ios_base::eofbit;
return __beg;
@@ -2180,7 +2179,7 @@
// __months array with the same index points to a month, and that
// month's abbreviated form.
// NB: Also assumes that an abbreviated name is a subset of the name.
- if (!__err)
+ if (!__err && __beg != __end)
{
size_t __pos = __traits_type::length(__months[__tmpmon]);
__tp._M_months(__months);
@@ -2195,9 +2194,9 @@
if (__len != __pos)
__err |= ios_base::failbit;
}
- if (!__err)
- __tm->tm_mon = __tmpmon;
}
+ if (!__err)
+ __tm->tm_mon = __tmpmon;
if (__beg == __end)
__err |= ios_base::eofbit;