xen-troops / displ_be

GNU General Public License v2.0
2 stars 8 forks source link

Potential crash because of exception in WL event handler #112

Open iusyk opened 4 years ago

iusyk commented 4 years ago

Description

Event handler OnDevice is registered in wl_drm_listener The code of the handler make the instance(in heap) of type DisplayWayland. The class DisplayWayland inherits the Drm::Display, the ctor of which can throw the exception (type Exception) In general - event handler must not throw the exception because there are not any guarantees that C code can handle it see code

void WaylandZCopy::onDevice(const string& name) { lock_guard lock(mMutex);

LOG(mLog, DEBUG) << "onDevice name: " << name;

mDrmDevice.reset(new Drm::DisplayWayland(name));

authenticate();

}

Display::Display () { ... if (mDrmFd < 0) { throw Exception("Cannot open DRM device: " + mName, errno); } ... if (drmGetCap(mDrmFd, DRM_CAP_DUMB_BUFFER, &hasDumb) < 0 || !hasDumb) { throw Exception("Drm device does not support dumb buffers", errno); } }

Solution

Wrap code inside OnDevice in block try{}catch(const Exception&){}

iusyk commented 4 years ago

fix https://github.com/xen-troops/displ_be/pull/129