Skip to content
Tcl Source Code History Of Ticket 3606139fffffffff
Login

History Of Ticket 3606139fffffffff

Artifacts Associated With Ticket 3606139fffffffff

  1. Ticket change [a7028def52] (rid 98711) by tgl on 2013-02-26 23:47:28:

    1. assignee initialized to: "pvgoran"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      The attached test case crashes the latest tclsh I have handy (8.5.11)
      
      This is derived from a test case that was sent to the Postgres security list.  The Postgres project is currently thinking of treating this as just a regular bug and not a security issue, because as far as we can tell the potential damage is limited to a null-pointer dereference.  But we thought we'd let you know about it first to see if you feel it needs to be treated as a security issue.  If so, we'll need to organize coordinated releases.
      
      Here's the analysis I sent to the Postgres security list:
      
      I looked into this, and find that the core of the problem is that
      parseqatom() is not defending itself against a NULL result from
      parsebranch().  See this bit of code:
      
          if (!(SEE('|') || SEE(stopper) || SEE(EOS)))
              t->right = parsebranch(v, stopper, type, s2, rp, 1);
          else
          {
              EMPTYARC(s2, rp);
              t->right = subre(v, '=', 0, s2, rp);
          }
          assert(SEE('|') || SEE(stopper) || SEE(EOS));
          t->flags |= COMBINE(t->flags, t->right->flags);
      
      If parsebranch (or subre for that matter) returns NULL, the
      t->right->flags reference will obviously crash.
      
      It turns out that parsebranch usually returns a valid struct subre
      pointer even after an error, but it has two "NOERRN()" macros
      (essentially "if (error occurred) return NULL") in places where only
      an out-of-memory or regex-too-complex error would trigger the error
      response.  This example case is provoking the regex-too-complex error.
      
      This bug is aboriginal in Spencer's code.  The reason we've not seen it
      reported before appears to be (a) typical errors such as regex syntax
      errors don't end up returning NULL from parsebranch, and (2) you don't
      get to the vulnerable code in parseqatom unless the regex has been found
      to contain "messy stuff" (capturing parens, back reference, or
      short/long preference clash).
      
      The attached patch fixes it.  The added error check in parseqatom() is
      the necessary fix, the additional check in parsebranch() is just
      intended to not let processing continue after we know there's an error.
      
      I'm not sure whether we should treat this as a security problem or just
      fix it and be done.  AFAICS there is no risk of anything worse than a
      null pointer dereference (no possibility of privilege escalation or
      information leakage).  We've been less than consistent in the past as to
      how to deal with simple crash cases like this; some have been treated as
      security issues, but many more have just been handled as ordinary bugs.
      
      
      BTW, credit for finding this issue goes to Tomasz Karlik <[email protected]>
      
      
    4. foundin initialized to: "obsolete: 8.5.11"
    5. is_private initialized to: "1"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "tgl"
    10. subsystem initialized to: "43. Regexp"
    11. title initialized to: "missing error check allows regexp to crash Tcl"
    12. type initialized to: "Bug"
  2. Add attachment "tcl_crash.tcl" [6e7fd85226] (rid 100152) by tgl on 2013-02-27 06:47:34.

  3. Ticket change [c011a95127] (rid 102348) by tgl on 2013-02-27 06:47:34:

    1. icomment:
      
      
      File Added - 461004: tcl_crash.tcl
      
      
      
    2. login: "tgl"
    3. mimetype: "text/plain"
    4. username: "tgl"
  4. Add attachment "regex-crash-fix.patch" [94dbcd55f8] (rid 106072) by tgl on 2013-02-27 06:48:20.

  5. Ticket change [6d9ddb7f69] (rid 128737) by tgl on 2013-02-27 06:48:20:

    1. icomment:
      
      
      File Added - 461005: regex-crash-fix.patch
      
      
      
    2. login: "tgl"
    3. mimetype: "text/plain"
    4. username: "tgl"
  6. Ticket change [2e37bcfaa9] (rid 119188) by nijtmans on 2013-02-27 15:24:37:

    1. assignee changed to: "nijtmans"
    2. closedate changed to: "2013-02-27T08:24:37"
    3. closer changed to: "nijtmans"
    4. foundin changed to: "obsolete: 8.4.19"
    5. icomment:
      Agreed with the analysis. I see no reason to consider this a security bug as well.
      
      Fixed now on core-8-4-branch, core-8-5-branch and trunk.
      
      Many thanks!
      
      
    6. login: "nijtmans"
    7. mimetype: "text/plain"
    8. resolution changed to: "Fixed"
    9. status changed to: "Closed"
    10. username: "nijtmans"
  7. Ticket change [772b5c08af] (rid 89734) by dgp on 2013-02-27 19:09:06:

    1. icomment:
      Is Tom Lane (tgl) aware of the other recent regexp fix in Tcl?
      Tcl Bug 3604074.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  8. Ticket change [b5c0481ee3] (rid 125298) by dgp on 2013-02-27 19:18:44:

    1. icomment:
      Can't we craft that test case using [string repeat], etc.
      instead of such an ugly literal?  Is that addition to the
      contents the cause of fossil now thinking regexp.test
      is a binary file?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [6509bb331b] (rid 92877) by nijtmans on 2013-02-27 20:32:42:

    1. icomment:
      I tried to use [string repeat] but that leads to memory errors in stead of the expected error message.
      Anyway, wrapping it over multiple lines works. I'm open to ideas for further improvmement.
      
      
    2. login: "nijtmans"
    3. mimetype: "text/plain"
    4. username: "nijtmans"
  10. Ticket change [b08320fc44] (rid 97992) by tgl on 2013-02-27 21:54:59:

    1. icomment:
      > Is Tom Lane (tgl) aware of the other recent regexp fix in Tcl?
      > Tcl Bug 3604074.
      
      I'll take a look, thanks for the pointer.
      
      
    2. login: "tgl"
    3. mimetype: "text/plain"
    4. username: "tgl"