Expand build_path() function to handle empty dir arguments gracefully

When passing an empty string as a directory, the function would produce
filenames starting with a slash even when the given file_name is not an absolute
path. Defaulting to the root directory is likely never intended and might
conveivably be dangerous. The middle "/" is now skipped also if dir is an empty
string.
This commit is contained in:
Christian Kreibich 2022-05-13 14:18:22 -07:00
parent 4d1b9f4a08
commit 9d59a48ae2
3 changed files with 14 additions and 7 deletions

View file

@ -79,7 +79,10 @@ test build_path_compressed()
/usr/local/bro/share/bro/somefile.zeek
/usr/local/bro/somefile.zeek
===============================
test build_full_path()
test build_path()
===============================
/home/bro//policy/somefile.zeek
/home/bro/policy/somefile.zeek
/usr/local/bro/share/bro/somefile.zeek
policy/somefile.zeek
/usr/local/bro/share/bro/somefile.zeek
/policy/somefile.zeek