selinux: handle getcon_raw producing a NULL pointer, despite returning 0

Previously, we assumed that success meant we definitely got a valid
pointer. There is at least one edge case where this is not true (i.e.,
we can get both a 0 return value, and *also* a NULL pointer):
4246bb550d/libselinux/src/procattr.c (L175)

When this case occurrs, if we don't check the pointer we SIGSEGV in
early initialization.
This commit is contained in:
Axel Rasmussen 2020-07-23 10:54:23 -07:00 committed by Yu Watanabe
parent d05f7b5007
commit 199a892218
1 changed files with 2 additions and 1 deletions

View File

@ -50,7 +50,8 @@ int mac_selinux_setup(bool *loaded_policy) {
/* Already initialized by somebody else? */
r = getcon_raw(&con);
if (r == 0) {
/* getcon_raw can return 0, and still give us a NULL pointer. */
if (r == 0 && con) {
initialized = !streq(con, "kernel");
freecon(con);
}