[PATCH] D94950: [clang][lex] Speculative fix for buffer overrun on raw string parse

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 15 07:10:52 PDT 2021


jansvoboda11 added inline comments.


================
Comment at: clang/lib/Lex/LiteralSupport.cpp:1639
       const char *Prefix = ThisTokBuf;
-      while (ThisTokBuf[0] != '(')
+      while (ThisTokBuf - Prefix < 16 && ThisTokBuf[0] != '(')
         ++ThisTokBuf;
----------------
beccadax wrote:
> Nit: "16" is a magic number; it might be better to use a constant or comment to document its significance (raw strings can only have 16-character delimiters).
> 
> (I believe this is C++11 [lex.string]p2, but I've never written one of the citation comments you see in clang, so I'm not sure if you should cite a later standard.)
Good point on the magic number, I'm going to extract that.

I'll check how the citations are written and add one here.


================
Comment at: clang/lib/Lex/LiteralSupport.cpp:1647
       ThisTokEnd -= ThisTokBuf - Prefix;
       assert(ThisTokEnd >= ThisTokBuf && "malformed raw string literal");
 
----------------
beccadax wrote:
> In your shoes, I would also have promoted this to a real check, but if you think that's overkill I'm fine with leaving it as it is.
I think that's sensible, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94950/new/

https://reviews.llvm.org/D94950



More information about the cfe-commits mailing list