Commit 6344d8ea by Kimmo Kinnunen Committed by Commit Bot

Fix a crash on checking NVIDIA driver version with incorrect X11 DISPLAY

Check if the display was valid (non-null Display pointer) before querying NVCTRL X11 extension. Bug: 840249 Change-Id: I299f87e2eb150d56649dd71c7becbe8f8abf7841 Reviewed-on: https://chromium-review.googlesource.com/c/1392906Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent eb278cb0
...@@ -30,7 +30,7 @@ bool GetNvidiaDriverVersionWithXNVCtrl(std::string *version) ...@@ -30,7 +30,7 @@ bool GetNvidiaDriverVersionWithXNVCtrl(std::string *version)
Display *display = XOpenDisplay(nullptr); Display *display = XOpenDisplay(nullptr);
if (XNVCTRLQueryExtension(display, &eventBase, &errorBase)) if (display && XNVCTRLQueryExtension(display, &eventBase, &errorBase))
{ {
int screenCount = ScreenCount(display); int screenCount = ScreenCount(display);
for (int screen = 0; screen < screenCount; ++screen) for (int screen = 0; screen < screenCount; ++screen)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <iostream> #include <iostream>
#include "common/platform.h" #include "common/platform.h"
#include "common/system_utils.h"
#include "gpu_info_util/SystemInfo.h" #include "gpu_info_util/SystemInfo.h"
using namespace angle; using namespace angle;
...@@ -99,4 +100,31 @@ TEST(PrintSystemInfoTest, Print) ...@@ -99,4 +100,31 @@ TEST(PrintSystemInfoTest, Print)
#endif #endif
} }
TEST(PrintSystemInfoTest, GetSystemInfoNoCrashOnInvalidDisplay)
{
#if defined(SYSTEM_INFO_IMPLEMENTED) && defined(ANGLE_USE_X11)
const char kX11DisplayEnvVar[] = "DISPLAY";
const char kInvalidDisplay[] = "124:";
std::string previous_display = GetEnvironmentVar(kX11DisplayEnvVar);
SetEnvironmentVar(kX11DisplayEnvVar, kInvalidDisplay);
SystemInfo info;
// This should not crash.
GetSystemInfo(&info);
if (previous_display.empty())
{
UnsetEnvironmentVar(kX11DisplayEnvVar);
}
else
{
SetEnvironmentVar(kX11DisplayEnvVar, previous_display.c_str());
}
#elif defined(SYSTEM_INFO_IMPLEMENTED)
std::cerr << "GetSystemInfo not implemented, skipping" << std::endl;
#else
std::cerr << "GetSystemInfo X11 test not applicable, skipping" << std::endl;
#endif
}
} // anonymous namespace } // anonymous namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment