Skip to content

Commit ab5eb82

Browse files
authored
Merge pull request #2054 from yingcong-wu/yc-0903-handle-option-exception
[DeviceSanitizer] refine option parsing
2 parents 35b83de + fcdc6a7 commit ab5eb82

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

source/loader/layers/sanitizer/asan_options.hpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ struct AsanOptions {
4242

4343
private:
4444
AsanOptions(logger::Logger &logger) {
45-
auto OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
45+
std::optional<EnvVarMap> OptionsEnvMap;
46+
try {
47+
OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
48+
} catch (const std::invalid_argument &e) {
49+
std::stringstream SS;
50+
SS << "<SANITIZER>[ERROR]: ";
51+
SS << e.what();
52+
logger.always(SS.str().c_str());
53+
die("Sanitizer failed to parse options.\n");
54+
}
55+
4656
if (!OptionsEnvMap.has_value()) {
4757
return;
4858
}
@@ -74,8 +84,8 @@ struct AsanOptions {
7484
Opt = false;
7585
} else {
7686
std::stringstream SS;
77-
SS << "<SANITIZER>[ERROR]: \"" << Name << "\" is set to \""
78-
<< Value << "\", which is not an valid setting. ";
87+
SS << "\"" << Name << "\" is set to \"" << Value
88+
<< "\", which is not an valid setting. ";
7989
SS << "Acceptable input are: for enable, use:";
8090
for (auto &S : TrueStrings) {
8191
SS << " \"" << S << "\"";
@@ -86,7 +96,8 @@ struct AsanOptions {
8696
SS << " \"" << S << "\"";
8797
}
8898
SS << ".";
89-
die(SS.str().c_str());
99+
logger.error(SS.str().c_str());
100+
die("Sanitizer failed to parse options.\n");
90101
}
91102
}
92103
};
@@ -106,9 +117,10 @@ struct AsanOptions {
106117
}
107118
MaxQuarantineSizeMB = temp_long;
108119
} catch (...) {
109-
die("<SANITIZER>[ERROR]: \"quarantine_size_mb\" should be "
110-
"an positive integer that smaller than or equal to "
111-
"4294967295.");
120+
logger.error("\"quarantine_size_mb\" should be "
121+
"an integer in range[0, {}].",
122+
UINT32_MAX);
123+
die("Sanitizer failed to parse options.\n");
112124
}
113125
}
114126

@@ -120,10 +132,12 @@ struct AsanOptions {
120132
if (MinRZSize < 16) {
121133
MinRZSize = 16;
122134
logger.warning("Trying to set redzone size to a "
123-
"value less than 16 is ignored");
135+
"value less than 16 is ignored.");
124136
}
125137
} catch (...) {
126-
die("<SANITIZER>[ERROR]: \"redzone\" should be an integer");
138+
logger.error(
139+
"\"redzone\" should be an integer in range[0, 16].");
140+
die("Sanitizer failed to parse options.\n");
127141
}
128142
}
129143

@@ -135,10 +149,12 @@ struct AsanOptions {
135149
if (MaxRZSize > 2048) {
136150
MaxRZSize = 2048;
137151
logger.warning("Trying to set max redzone size to a "
138-
"value greater than 2048 is ignored");
152+
"value greater than 2048 is ignored.");
139153
}
140154
} catch (...) {
141-
die("<SANITIZER>[ERROR]: \"max_redzone\" should be an integer");
155+
logger.error(
156+
"\"max_redzone\" should be an integer in range[0, 2048].");
157+
die("Sanitizer failed to parse options.\n");
142158
}
143159
}
144160
}

0 commit comments

Comments
 (0)