lilv_state_new_from_file: avoid segfault when path does not exist
Concretely:
⟩ file foo/
foo/: directory
⟩ # before:
⟩ jalv -l foo/ http://open-music-kontrollers.ch/lv2/moony#a2xa2
fish: Job 1, 'jalv -l foo/ http://ope…' terminated by signal SIGSEGV (Address boundary error)
⟩ # after:
⟩ LD_PRELOAD=../lilv/build/liblilv-0.so jalv -l foo/ http://open-music-kontrollers.ch/lv2/moony#a2xa2
lilv_state_new_from_file(): error: Path `foo//state.ttl' cannot be made canonical.
error: Failed to load state from foo/
The call trace leading to the segfault is something like:
-
jalv_open
callslilv_state_new_from_file
if the load argument is given. It passesload + "/state.ttl"
ifload
is a directory, else it passesload
directly. - The first thing
lilv_state_new_from_file
does is callzix_canonical_path
on the path (looking at the POSIX codepath only, not Windows).- This calls
realpath(path, buffer)
which returnsNULL
if the operation failed or ifzix_calloc
fails. -
zix_canonical_path
is therefore returningNULL
.
- This calls
- We call
serd_node_new_file_uri
with the previous result. The first thing this does is callstrlen
on its argument, meaning we segfault.
I've therefore added a check in LILV to avoid calling serd_node_new_file_uri
with a NULL pointer.
Edited by Théo Lebrun