NVIDIA / egl-wayland

The EGLStream-based Wayland external platform
MIT License
275 stars 44 forks source link

Fix interface type checks #36

Closed danvd closed 2 years ago

danvd commented 2 years ago

This does 3 things:

  1. Makes WL_CHECK_INTERFACE_TYPE check interface pointers first because it's faster.
  2. Adds 3rd parameter to WL_CHECK_INTERFACE_TYPE (string with interface name). Real interface names do not contain "_interface" postfix in their names.
  3. Removes dladdr() call from wlEglCheckInterfaceType and checks interface names directly. dladdr() returns DL_info, which in turn includes name of shared object that owns passed adress. And it's not interface name, but process or library path, e.g. "/usr/bin/alacritty" or "/usr/lib/libegl-renderer.so.1".

Fixes at least #34

danvd commented 2 years ago

@erik-kz Will you have some time to review this? Thanks.

erik-kz commented 2 years ago

Thanks for submitting the patch, and apologies for the slow review. While this would be sufficient to fix the rust issue, the problem is that because of the way external platform handles work, wlEglCheckInterfaceType needs to be safe to be called with an arbitrary pointer, even if it doesn't point to a wl_interface struct. Hence, it may not be safe to simply pass interface->name to strcmp since we can't be certain that memory is addressable.

To be safe, we need to check that we can indeed dereference a) interface->name, and b) the interface name itself. This is what I've done in https://github.com/NVIDIA/egl-wayland/commit/2eb4628d64a8297fb4c08aa796fdf33ff54a670f if you're curious.

danvd commented 2 years ago

Got it. Thank for the fix!