diff --git a/source/loader/layers/sanitizer/asan_options.hpp b/source/loader/layers/sanitizer/asan_options.hpp index 298639b73c..eb3f6bb03d 100644 --- a/source/loader/layers/sanitizer/asan_options.hpp +++ b/source/loader/layers/sanitizer/asan_options.hpp @@ -42,7 +42,17 @@ struct AsanOptions { private: AsanOptions(logger::Logger &logger) { - auto OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS"); + std::optional OptionsEnvMap; + try { + OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS"); + } catch (const std::invalid_argument &e) { + std::stringstream SS; + SS << "[ERROR]: "; + SS << e.what(); + logger.always(SS.str().c_str()); + die("Sanitizer failed to parse options.\n"); + } + if (!OptionsEnvMap.has_value()) { return; } @@ -74,8 +84,8 @@ struct AsanOptions { Opt = false; } else { std::stringstream SS; - SS << "[ERROR]: \"" << Name << "\" is set to \"" - << Value << "\", which is not an valid setting. "; + SS << "\"" << Name << "\" is set to \"" << Value + << "\", which is not an valid setting. "; SS << "Acceptable input are: for enable, use:"; for (auto &S : TrueStrings) { SS << " \"" << S << "\""; @@ -86,7 +96,8 @@ struct AsanOptions { SS << " \"" << S << "\""; } SS << "."; - die(SS.str().c_str()); + logger.error(SS.str().c_str()); + die("Sanitizer failed to parse options.\n"); } } }; @@ -106,9 +117,10 @@ struct AsanOptions { } MaxQuarantineSizeMB = temp_long; } catch (...) { - die("[ERROR]: \"quarantine_size_mb\" should be " - "an positive integer that smaller than or equal to " - "4294967295."); + logger.error("\"quarantine_size_mb\" should be " + "an integer in range[0, {}].", + UINT32_MAX); + die("Sanitizer failed to parse options.\n"); } } @@ -120,10 +132,12 @@ struct AsanOptions { if (MinRZSize < 16) { MinRZSize = 16; logger.warning("Trying to set redzone size to a " - "value less than 16 is ignored"); + "value less than 16 is ignored."); } } catch (...) { - die("[ERROR]: \"redzone\" should be an integer"); + logger.error( + "\"redzone\" should be an integer in range[0, 16]."); + die("Sanitizer failed to parse options.\n"); } } @@ -135,10 +149,12 @@ struct AsanOptions { if (MaxRZSize > 2048) { MaxRZSize = 2048; logger.warning("Trying to set max redzone size to a " - "value greater than 2048 is ignored"); + "value greater than 2048 is ignored."); } } catch (...) { - die("[ERROR]: \"max_redzone\" should be an integer"); + logger.error( + "\"max_redzone\" should be an integer in range[0, 2048]."); + die("Sanitizer failed to parse options.\n"); } } }