Skip to content

Commit 6344d8e

Browse files
kkinnunenCommit Bot
authored and
Commit Bot
committed
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/1392906 Reviewed-by: Geoff Lang <[email protected]> Reviewed-by: Corentin Wallez <[email protected]> Commit-Queue: Geoff Lang <[email protected]>
1 parent eb278cb commit 6344d8e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/gpu_info_util/SystemInfo_x11.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool GetNvidiaDriverVersionWithXNVCtrl(std::string *version)
3030

3131
Display *display = XOpenDisplay(nullptr);
3232

33-
if (XNVCTRLQueryExtension(display, &eventBase, &errorBase))
33+
if (display && XNVCTRLQueryExtension(display, &eventBase, &errorBase))
3434
{
3535
int screenCount = ScreenCount(display);
3636
for (int screen = 0; screen < screenCount; ++screen)

src/tests/util_tests/PrintSystemInfoTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <iostream>
1313

1414
#include "common/platform.h"
15+
#include "common/system_utils.h"
1516
#include "gpu_info_util/SystemInfo.h"
1617

1718
using namespace angle;
@@ -99,4 +100,31 @@ TEST(PrintSystemInfoTest, Print)
99100
#endif
100101
}
101102

103+
TEST(PrintSystemInfoTest, GetSystemInfoNoCrashOnInvalidDisplay)
104+
{
105+
#if defined(SYSTEM_INFO_IMPLEMENTED) && defined(ANGLE_USE_X11)
106+
const char kX11DisplayEnvVar[] = "DISPLAY";
107+
const char kInvalidDisplay[] = "124:";
108+
std::string previous_display = GetEnvironmentVar(kX11DisplayEnvVar);
109+
SetEnvironmentVar(kX11DisplayEnvVar, kInvalidDisplay);
110+
SystemInfo info;
111+
112+
// This should not crash.
113+
GetSystemInfo(&info);
114+
115+
if (previous_display.empty())
116+
{
117+
UnsetEnvironmentVar(kX11DisplayEnvVar);
118+
}
119+
else
120+
{
121+
SetEnvironmentVar(kX11DisplayEnvVar, previous_display.c_str());
122+
}
123+
#elif defined(SYSTEM_INFO_IMPLEMENTED)
124+
std::cerr << "GetSystemInfo not implemented, skipping" << std::endl;
125+
#else
126+
std::cerr << "GetSystemInfo X11 test not applicable, skipping" << std::endl;
127+
#endif
128+
}
129+
102130
} // anonymous namespace

0 commit comments

Comments
 (0)