alex-courtis / way-displays

way-displays: Auto Manage Your Wayland Displays
MIT License
241 stars 12 forks source link

don't walk over sun_path size limit in snprintf() #35

Closed nekopsykose closed 2 years ago

nekopsykose commented 2 years ago

otherwise building on ppc64le fails with:

src/sockets.c: In function 'socket_path':
src/sockets.c:98:62: error: '%s' directive output may be truncated writing up to 107 bytes into a region of size 104 [-Werror=format-truncation=]
   98 |                 snprintf(addr->sun_path, sun_path_size, "/tmp%s", name);
      |                                                              ^~
src/sockets.c:98:17: note: 'snprintf' output between 5 and 112 bytes into a destination of size 108
   98 |                 snprintf(addr->sun_path, sun_path_size, "/tmp%s", name);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

this is caused by the "/tmp%s" format specifier:
snprintf(addr->sun_path, sun_path_size, "/tmp%s", name);
being 4 bytes longer than sun_path/sun_path_size (when added to the size of name), so make name shorter by 4 than the sun_path_size so it fits

as an aside, i have no idea why this doesn't fail on any other arch. technically on all of them that is doing a size = size + 4, so they should all be truncated...

alex-courtis commented 2 years ago

Many thanks! 1.5.1 released.