file: prevent writes beyond end of uh_buf on enumerating directories
authorJo-Philipp Wich <[email protected]>
Sat, 5 Apr 2025 13:21:52 +0000 (15:21 +0200)
committerJo-Philipp Wich <[email protected]>
Sat, 5 Apr 2025 13:21:52 +0000 (15:21 +0200)
commit3d6f01b9d01a6ffa9e73705112cd51bfd98ec2fc
tree003e39d01f5b7233d910a8ce77868f3a6c56db5b
parentfad0d05da757dcd73abc2beb02ce4e4edf83ac3d
file: prevent writes beyond end of uh_buf on enumerating directories

Under some circumstances, e.g. when enumerating the entries of a directory
hierarchy close to 4096 bytes total path length, the sprintf() used to
conatenate the filename might write beyond the end of the PATH_MAX sized
global `uh_buf` scratch buffer used to form the complete file paths during
enumeration, potentially clobbering neighboring data structures, such as
the global configuration struct.

Prevent this issue by passing the amount of remaining available bytes for
the name componentent to the `list_entries()` function and passing this
value to `snprintf()` therein.

Signed-off-by: Jo-Philipp Wich <[email protected]>
file.c