[compiler-rt] [[[[[scudo] simplify flag parser out of bounds logic (PR #72371)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 02:36:03 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Florian Mayer (fmayer)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/72371.diff
1 Files Affected:
- (modified) compiler-rt/lib/scudo/standalone/flags_parser.cpp (+9-9)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/72371
More information about the llvm-commits
mailing list