[compiler-rt] d1168df - [scudo] change allocation buffer size with env var (#71703)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 14:59:28 PST 2023
Author: Florian Mayer
Date: 2023-11-14T14:59:25-08:00
New Revision: d1168df2a46e6077d7dd1acc7e6302405dc8d610
URL: https://github.com/llvm/llvm-project/commit/d1168df2a46e6077d7dd1acc7e6302405dc8d610
DIFF: https://github.com/llvm/llvm-project/commit/d1168df2a46e6077d7dd1acc7e6302405dc8d610.diff
LOG: [scudo] change allocation buffer size with env var (#71703)
We don't allow SCUDO_OPTIONS to be preserved across SELinux transitions,
so introducing a more constrained one that we can preserve.
Added:
Modified:
compiler-rt/lib/scudo/standalone/flags.cpp
compiler-rt/lib/scudo/standalone/flags_parser.cpp
compiler-rt/lib/scudo/standalone/flags_parser.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/flags.cpp b/compiler-rt/lib/scudo/standalone/flags.cpp
index de5153b288b14e3..f498edfbd326ac8 100644
--- a/compiler-rt/lib/scudo/standalone/flags.cpp
+++ b/compiler-rt/lib/scudo/standalone/flags.cpp
@@ -68,6 +68,9 @@ void initFlags() {
Parser.parseString(getCompileDefinitionScudoDefaultOptions());
Parser.parseString(getScudoDefaultOptions());
Parser.parseString(getEnv("SCUDO_OPTIONS"));
+ if (const char *V = getEnv("SCUDO_ALLOCATION_RING_BUFFER_SIZE")) {
+ Parser.parseStringPair("allocation_ring_buffer_size", V);
+ }
}
} // namespace scudo
diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.cpp b/compiler-rt/lib/scudo/standalone/flags_parser.cpp
index be39fcd4f8879ba..10da6754be821bf 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 <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -80,7 +81,7 @@ void FlagParser::parseFlag() {
++Pos;
Value = Buffer + ValueStart;
}
- if (!runHandler(Name, Value))
+ if (!runHandler(Name, Value, '='))
reportError("flag parsing failed.");
}
@@ -122,10 +123,16 @@ inline bool parseBool(const char *Value, bool *b) {
return false;
}
-bool FlagParser::runHandler(const char *Name, const char *Value) {
+void FlagParser::parseStringPair(const char *Name, const char *Value) {
+ if (!runHandler(Name, Value, '\0'))
+ reportError("flag parsing failed.");
+}
+
+bool FlagParser::runHandler(const char *Name, const char *Value,
+ const char Sep) {
for (u32 I = 0; I < NumberOfFlags; ++I) {
const uptr Len = strlen(Flags[I].Name);
- if (strncmp(Name, Flags[I].Name, Len) != 0 || Name[Len] != '=')
+ if (strncmp(Name, Flags[I].Name, Len) != 0 || Name[Len] != Sep)
continue;
bool Ok = false;
switch (Flags[I].Type) {
@@ -136,8 +143,17 @@ bool FlagParser::runHandler(const char *Name, const char *Value) {
break;
case FlagType::FT_int:
char *ValueEnd;
- *reinterpret_cast<int *>(Flags[I].Var) =
- static_cast<int>(strtol(Value, &ValueEnd, 10));
+ long V = strtol(Value, &ValueEnd, 10);
+ static_assert(INT_MAX <= LONG_MAX);
+ static_assert(INT_MIN >= LONG_MIN);
+ // 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) {
+ reportInvalidFlag("int", Value);
+ return false;
+ }
+ *reinterpret_cast<int *>(Flags[I].Var) = static_cast<int>(V);
Ok =
*ValueEnd == '"' || *ValueEnd == '\'' || isSeparatorOrNull(*ValueEnd);
if (!Ok)
diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.h b/compiler-rt/lib/scudo/standalone/flags_parser.h
index ba832adbd90982d..ded496fda3b9787 100644
--- a/compiler-rt/lib/scudo/standalone/flags_parser.h
+++ b/compiler-rt/lib/scudo/standalone/flags_parser.h
@@ -27,6 +27,7 @@ class FlagParser {
void *Var);
void parseString(const char *S);
void printFlagDescriptions();
+ void parseStringPair(const char *Name, const char *Value);
private:
static const u32 MaxFlags = 20;
@@ -45,7 +46,7 @@ class FlagParser {
void skipWhitespace();
void parseFlags();
void parseFlag();
- bool runHandler(const char *Name, const char *Value);
+ bool runHandler(const char *Name, const char *Value, char Sep);
};
void reportUnrecognizedFlags();
More information about the llvm-commits
mailing list