Skip to content

loader: work around lstat()/EACCES regression in _g_local_file_info_get()

In glib commit 71e7b5800a31 ("Handle MLS selinux policy better",
2010-07-08), which was made for
<https://bugzilla.gnome.org/show_bug.cgi?id=623692>, an lstat() failure
with error code EACCES was *masked* in function _g_local_file_info_get().

Consequently, if osinfo_loader_find_files() calls g_file_query_info() on a
file that is inaccessible due to (e.g.) a missing "x" (search) permission
on a leading directory, then g_file_query_info() succeeds, our
"skipMissing" branch is dead, g_file_info_get_attribute_uint32() is
reached, and it returns G_FILE_TYPE_UNKNOWN.

As a consequence, the outer osinfo_loader_process_default_path() function
can fail, even though it passes skipMissing=TRUE to
osinfo_loader_process_list(). Example:

> $ HOME=/root \
>   OSINFO_SYSTEM_DIR=/usr/share/osinfo \
>   build/tools/osinfo-query os
> Error loading OS data: Can't read path /root/.config/osinfo

Arguably, this situation should be handled by simply skipping the
inaccessible path, as if all leading directories could be searched, and
only the last pathname compontent (the filename entry) didn't exist in its
direct parent directory.

The glib regression was reported in 2017:

  https://bugzilla.gnome.org/show_bug.cgi?id=777187

and then migrated to gitlab:

  https://gitlab.gnome.org/GNOME/glib/-/issues/1237

but it's still not solved today.

Work around the issue by honoring "skipMissing" on the G_FILE_TYPE_UNKNOWN
branch. Demonstration:

> $ HOME=/root \
>   OSINFO_SYSTEM_DIR=/usr/share/osinfo \
>   build/tools/osinfo-query os
>
>
> ** (osinfo-query:9924): WARNING **: 13:23:12.776: Can't read path /root/.config/osinfo
>  Short ID       | Name             | Version | ID
> ----------------+------------------+---------+----------------------------------------
>  alpinelinux3.5 | Alpine Linux 3.5 | 3.5     | http://alpinelinux.org/alpinelinux/3.5
> ...

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2051559
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

Merge request reports