[Mesa-dev] [PATCH] swr/rast: do not crash on NULL strings returned by getenv

Emil Velikov emil.l.velikov at gmail.com
Mon Sep 18 10:29:21 UTC 2017


From: Bernhard Rosenkraenzer <bero at lindev.ch>

The current convinince 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.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101832
Fixes: a25093de718 ("swr/rast: Implement JIT shader caching to disk")
Cc: Tim Rowley <timothy.o.rowley at intel.com>
Cc: Laurent Carlier <lordheavym at gmail.com>
Cc: Bernhard Rosenkraenzer <bero at lindev.ch>
[Emil Velikov: make an actual commit from the misc diff]
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/gallium/drivers/swr/rasterizer/core/utils.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/swr/rasterizer/core/utils.h b/src/gallium/drivers/swr/rasterizer/core/utils.h
index b096d2120cb..3c849e82d3b 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 *o = getenv(variableName.c_str());
+    output = o ? std::string(o) : std::string();
 #endif
 
     return output;
-- 
2.14.1



More information about the mesa-dev mailing list