[PATCH] D97129: [Support] unsafe pointer arithmetic in llvm_regcomp()
Brad Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 3 16:59:53 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG877c84acd466: [Support] unsafe pointer arithmetic in llvm_regcomp() (authored by Miod Vallat <miod at online.fr>, committed by brad).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97129/new/
https://reviews.llvm.org/D97129
Files:
llvm/lib/Support/regcomp.c
Index: llvm/lib/Support/regcomp.c
===================================================================
--- llvm/lib/Support/regcomp.c
+++ llvm/lib/Support/regcomp.c
@@ -249,10 +249,10 @@
*/
#define PEEK() (*p->next)
#define PEEK2() (*(p->next+1))
-#define MORE() (p->next < p->end)
-#define MORE2() (p->next+1 < p->end)
+#define MORE() (p->end - p->next > 0)
+#define MORE2() (p->end - p->next > 1)
#define SEE(c) (MORE() && PEEK() == (c))
-#define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
+#define SEETWO(a, b) (MORE2() && PEEK() == (a) && PEEK2() == (b))
#define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
#define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
#define NEXT() (p->next++)
@@ -800,15 +800,17 @@
int invert = 0;
/* Dept of Truly Sickening Special-Case Kludges */
- if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
- EMIT(OBOW, 0);
- NEXTn(6);
- return;
- }
- if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
- EMIT(OEOW, 0);
- NEXTn(6);
- return;
+ if (p->end - p->next > 5) {
+ if (strncmp(p->next, "[:<:]]", 6) == 0) {
+ EMIT(OBOW, 0);
+ NEXTn(6);
+ return;
+ }
+ if (strncmp(p->next, "[:>:]]", 6) == 0) {
+ EMIT(OEOW, 0);
+ NEXTn(6);
+ return;
+ }
}
if ((cs = allocset(p)) == NULL) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97129.405833.patch
Type: text/x-patch
Size: 1300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220204/212d344d/attachment.bin>
More information about the llvm-commits
mailing list