- 
                Notifications
    
You must be signed in to change notification settings  - Fork 237
 
Restore buffer after an ACCEPT inside an scan substring block #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
        
          
                testdata/testoutput2
              
                Outdated
          
        
      | 
               | 
          ||
| /(a)(b+)(*scs:(1)a(*ACCEPT))(\2)/ | ||
| abbb | ||
| 0: abb | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this the current/expected output in 10.45 and HEAD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This patch is a bugfix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not being clear enough, but the point I was trying to make is that the test case doesn't show the bug, at least on my system:
PCRE2 version 10.45 2025-02-05 (8-bit)
  re> /(a)(b+)(*scs:(1)a(*ACCEPT))(\2)/BI
------------------------------------------------------------------
        Bra
        CBra 1
        a
        Ket
        CBra 2
        b+
        Ket
        Scan substring
      1 Capture ref
        a
        *ASSERT_ACCEPT
        Ket
        CBra 3
        \2
        Ket
        Ket
        End
------------------------------------------------------------------
Capture group count = 3
Max back reference = 2
First code unit = 'a'
Subject length lower bound = 1
data> abbb
 0: abb
 1: a
 2: b
 3: b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. The (PCRE2_SIZE)(mb->end_subject - eptr) < length in line 488 is 18446744073709551613 < length and does not true. A better test case is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test should be better. Thank you for noticing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are arguing over semantics, but yes, you are correct that this PR alone solves both bugs, including the subject over reads in match_ref that could cause crashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for confirming! I will include only this fix in the 10.46 security release, in order to make minimal changes in this release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw why not 10.45.1? The increase of major usually means new features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presume that moving to a 3 digit version number might be a good idea if we are going to do this regularly, but definitely would had been a bigger change and taken a lot longer than this took.
I had to admit I am impressed that it went so smoothly, including a CVE number being assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Changing the format of the version number to two digits has the potential to be disruptive to downstream consumers. Plus, we have API functions that expect a two-digit number, and the special VERSION pattern syntax...
It simply had to be 10.46.
Anyway, thanks to both of you for fixing this (Zoltan) and reviewing (Carlo).
| 
           Not a regression, as it seems to behave the same with or without this patch, but why is this correct? I was expecting   | 
    
| 
           The last one matches because of backtracking.   | 
    
| 
           Got it; do you have an example with (*ACCEPT) being relevant?  | 
    
          Probably something like this. There will be a buffer overread, although if the next character in the buffer is not   | 
    
| 
           I have decided I will make a dedicated security release, and notify the mailing list. For a widely-used library such as PCRE2, I would like to take this seriously. I should have acted on it sooner. That is my fault.  | 
    
No description provided.