[PATCH] D144100: [clang] Fix a bug that allowed some overflowing octal escape sequences

Sergei Barannikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 16 04:20:53 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG574e417460cd: [clang] Fix a bug that allowed some overflowing octal escape sequences (authored by barannikov88).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144100

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-escapes-delimited.c


Index: clang/test/Lexer/char-escapes-delimited.c
===================================================================
--- clang/test/Lexer/char-escapes-delimited.c
+++ clang/test/Lexer/char-escapes-delimited.c
@@ -58,6 +58,8 @@
 #if __WCHAR_MAX__ > 0xFFFF
   unsigned d = L'\o{37777777777}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
   unsigned e = L'\o{40000000000}'; // expected-error {{octal escape sequence out of range}}
+  unsigned f = L'\o{100000000000}'; // expected-error {{octal escape sequence out of range}}
+  unsigned g = L'\o{200000000000}'; // expected-error {{octal escape sequence out of range}}
 #else
   unsigned d = L'\o{177777}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
   unsigned e = L'\o{200000}'; // expected-error {{octal escape sequence out of range}}
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -263,7 +263,8 @@
         ThisTokBuf++;
         continue;
       }
-      if (ResultChar & 0x020000000)
+      // Check if one of the top three bits is set before shifting them out.
+      if (ResultChar & 0xE0000000)
         Overflow = true;
 
       ResultChar <<= 3;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144100.497962.patch
Type: text/x-patch
Size: 1261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230216/178b193a/attachment-0001.bin>


More information about the cfe-commits mailing list