From 5d3ce3a64090ccd3c38b235edf6228f41d003274 Mon Sep 17 00:00:00 2001 From: Jan Murawski Date: Wed, 14 Feb 2018 13:56:00 +0100 Subject: Handle unset $DISPLAY variable when using the offscreen platform Skip the initialization of a QOffscreenX11GLXContext and thereby fix a null pointer dereference if the environment variable $DISPLAY is unset or contains invalid information. Task-number: QTBUG-66423 Change-Id: Ideea510d1c63a4f6700839955d833cd10e3b0bbe Reviewed-by: Gatis Paeglis --- src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/offscreen') diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp index b46d94dfd3..93566220e8 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp @@ -71,6 +71,9 @@ QPlatformOpenGLContext *QOffscreenX11Integration::createPlatformOpenGLContext(QO if (!m_connection) m_connection.reset(new QOffscreenX11Connection); + if (!m_connection->display()) + return nullptr; + return new QOffscreenX11GLXContext(m_connection->x11Info(), context); } @@ -81,12 +84,13 @@ QOffscreenX11Connection::QOffscreenX11Connection() QByteArray displayName = qgetenv("DISPLAY"); Display *display = XOpenDisplay(displayName.constData()); m_display = display; - m_screenNumber = DefaultScreen(display); + m_screenNumber = m_display ? DefaultScreen(m_display) : -1; } QOffscreenX11Connection::~QOffscreenX11Connection() { - XCloseDisplay((Display *)m_display); + if (m_display) + XCloseDisplay((Display *)m_display); } class QOffscreenX11Info -- cgit v1.2.3