[compiler-rt] [[[[[scudo] simplify flag parser out of bounds logic (PR #72371)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 02:35:30 PST 2023
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/72371
almost NFC, just that now we accept INT_MIN and INT_MAX
as discussed in https://r.android.com/2831100, but I didn't add the *ValueEnd != Value check because I want to keep this change behaviour-keeping.
>From 93926eb8b31f9208ca38317e612a7a239e85a59e Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Wed, 15 Nov 2023 02:15:28 -0800
Subject: [PATCH] [scudo] simplify flag parser out of bounds logic
almost NFC, just that now we accept INT_MIN and INT_MAX
as discussed in https://r.android.com/2831100, but I didn't add the
*ValueEnd != Value check because I want to keep this change
behaviour-keeping.
---
.../lib/scudo/standalone/flags_parser.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.cpp b/compiler-rt/lib/scudo/standalone/flags_parser.cpp
index 6f9b23ea90e23cc..3d8c6f3789b4ccb 100644
--- a/compiler-rt/lib/scudo/standalone/flags_parser.cpp
+++ b/compiler-rt/lib/scudo/standalone/flags_parser.cpp
@@ -10,6 +10,7 @@
#include "common.h"
#include "report.h"
+#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -143,19 +144,18 @@ bool FlagParser::runHandler(const char *Name, const char *Value,
break;
case FlagType::FT_int:
char *ValueEnd;
+ errno = 0;
long V = strtol(Value, &ValueEnd, 10);
- // strtol returns LONG_MAX on overflow and LONG_MIN on underflow.
- // This is why we compare-equal here (and lose INT_MIN and INT_MAX as a
- // value, but that's okay)
- if (V >= INT_MAX || V <= INT_MIN) {
+ if (errno != 0 || // strtol failed (over or underflow)
+ V > INT_MAX || V < INT_MIN || // overflows integer
+ // contains unexpected characters
+ (*ValueEnd != '"' && *ValueEnd != '\'' &&
+ !isSeparatorOrNull(*ValueEnd))) {
reportInvalidFlag("int", Value);
- return false;
+ break;
}
*reinterpret_cast<int *>(Flags[I].Var) = static_cast<int>(V);
- Ok =
- *ValueEnd == '"' || *ValueEnd == '\'' || isSeparatorOrNull(*ValueEnd);
- if (!Ok)
- reportInvalidFlag("int", Value);
+ Ok = true;
break;
}
return Ok;
More information about the llvm-commits
mailing list