Fix heap buffer overflow in xdg_user_dir_lookup_with_fallback()

Commit 7968b781 ("Use GLib wrappers for memory allocation") replaced the allocation for $HOME-relative entries of user-dirs.dirs with g_strconcat (home_dir, "/", NULL). That buffer only has room for $HOME/, but the rest of the path is still appended to it in place, so the directory name is written past the end of the allocation.

Every start of the slideshow saver without --location hits this. It shows up as free(): invalid pointer under MALLOC_CHECK_=3, as a heap-buffer-overflow under AddressSanitizer, and occasionally as a SIGSEGV inside GTK in normal use.

This restores the original allocation size ($HOME + / + remaining path + NUL) while keeping the GLib allocator.

Tested by building savers/xdg-user-dir-lookup.c standalone with AddressSanitizer: the overflow is reported before the change and xdg_user_dir_lookup ("PICTURES") returns the expected path with no report after it. The full project was not rebuilt.

Closes #205 (closed)

Merge request reports

Loading
Loading