Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6062

mongoutils::str::stripTrailing accesses invalid iterators

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.7.8
    • 2.0.6, 2.1.1
    • Internal Code
    • ALL

    Description

      This is risky if std::string decides to reallocate to a smaller buffer when a string shrinks below some threshold of allocated space. A preferable implementation would walk backwards through the string until the first non-whitespace character, and then use erase() to erase a whole range.

      From coverity:

      API usage errors
      Undefined behavior may result; the program may crash or subtly misbehave.
      An invalid or past-the-end iterator is being used
       
      Defect 10072 (STATIC_C)
        Checker INVALIDATE_ITERATOR (subcategory none)
        File /src/mongo/util/mongoutils/str.h
        Function mongoutils::str::stripTrailing(std::basic_string<char, std::char_traits<char>, std::allocator<char>>&, const char *)
          /src/mongo/util/mongoutils/str.h, line: 209
          "erase" invalidates iterator "i".
                              s.erase(i);
          /src/mongo/util/mongoutils/str.h, line: 206
          Using invalid iterator "i".
                      while( s.begin() != i ) {

      Attachments

        Activity

          People

            Unassigned Unassigned
            schwerin@mongodb.com Andy Schwerin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: