Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-103940

Insufficient documentation in QRegularExpression variant of QString::indexOf(), results in random crash bug

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 6.3.0
    • Documentation
    • None
    • Windows
    • 5
    • 4712b0cd70 (qt/qtbase/6.3) 4712b0cd70 (qt/tqtc-qtbase/6.3)
    • Team B Foundation Sprint 59

    Description

      Documentation:

      qsizetype QString::indexOf(const QRegularExpression &re, qsizetype from = 0, QRegularExpressionMatch *rmatch = nullptr) const

      Returns the index position of the first match of the regular expression re in the string, searching forward from index position from. Returns -1 if re didn't match anywhere.

      If the match is successful and rmatch is not nullptr, it also writes the results of the match into the QRegularExpressionMatch object pointed to by rmatch.

       

      It should mention that the QString in question must remain valid as long as rmatch is used.

      QRegularExpressionMatch has constructors for both QString and QStringView and user of this function does not know which one is used. With just reading documentation of this function, it's very easy to write code that accesses deleted memory and results in random bugs:

       

      QRegularExpressionMatch match;
      if (getString().indexOf(QRegularExpression("m[aeiou]"), 0, &match) != -1)

      {   // here 'match' would access deleted memory as QString returned by getString() is already deleted. }

      OR

      QRegularExpressionMatch match;
      QString str = getString();
      if (str.left(5).indexOf(QRegularExpression("m[aeiou]"), 0, &match) != -1)

      {   // here 'match' would access deleted memory as QString returned by left() is already deleted. }

       

       

       

       

      Attachments

        For Gerrit Dashboard: QTBUG-103940
        # Subject Branch Project Status CR V

        Activity

          People

            javyas Jaishree Vyas
            -mtuokko- Mikko Tuokko
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change