From: Emil Velikov Date: Mon, 18 Sep 2017 10:29:21 +0000 (+0100) Subject: swr/rast: do not crash on NULL strings returned by getenv X-Git-Tag: upstream/18.1.0~5622 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21e271024d8e050b75361c2da2e5783100f2e87b;p=platform%2Fupstream%2Fmesa.git swr/rast: do not crash on NULL strings returned by getenv The current convenience function GetEnv feeds the results of getenv directly into std::string(). That is a bad idea, since the variable may be unset, thus we feed NULL into the C++ construct. The latter of which is not allowed and leads to a crash. v2: Better variable name, implicit char* -> std::string conversion (Eric) Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101832 Fixes: a25093de718 ("swr/rast: Implement JIT shader caching to disk") Cc: Tim Rowley Cc: Laurent Carlier Cc: Bernhard Rosenkraenzer [Emil Velikov: make an actual commit from the misc diff] Signed-off-by: Emil Velikov Reviewed-by: Eric Engestrom (v1) Reviewed-by: Laurent Carlier (v1) --- diff --git a/src/gallium/drivers/swr/rasterizer/core/utils.h b/src/gallium/drivers/swr/rasterizer/core/utils.h index b096d21..c926f6a 100644 --- a/src/gallium/drivers/swr/rasterizer/core/utils.h +++ b/src/gallium/drivers/swr/rasterizer/core/utils.h @@ -365,7 +365,8 @@ static INLINE std::string GetEnv(const std::string& variableName) output.resize(valueSize - 1); // valueSize includes null, output.resize() does not GetEnvironmentVariableA(variableName.c_str(), &output[0], valueSize); #else - output = getenv(variableName.c_str()); + char *env = getenv(variableName.c_str()); + output = env ? env : ""; #endif return output;