Skip to content

Commit

Permalink
libselinux: set free'd data to NULL
Browse files Browse the repository at this point in the history
Fixes segfault in selabel_open() on systems with SELinux disabled and without any
SELinux policy installed introduced by commit 5876aca ("libselinux: free
data on selabel open failure"):

    $ sestatus
    SELinux status:                 disabled

    $ cat /etc/selinux/config
    cat: /etc/selinux/config: No such file or directory

    $ matchpathcon /abc
    [1]    907999 segmentation fault (core dumped)  matchpathcon /abc

Signed-off-by: Petr Lautrbach <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
bachradsusi committed Jul 22, 2024
1 parent 2eb286b commit f398662
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions libselinux/src/label_backends_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ static void closef(struct selabel_handle *rec)
free(data->spec_arr);

free(data);
rec->data = NULL;
}

static struct selabel_lookup_rec *property_lookup(struct selabel_handle *rec,
Expand Down
1 change: 1 addition & 0 deletions libselinux/src/label_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ static void closef(struct selabel_handle *rec)
free(last_area);
}
free(data);
rec->data = NULL;
}

// Finds all the matches of |key| in the given context. Returns the result in
Expand Down
1 change: 1 addition & 0 deletions libselinux/src/label_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static void close(struct selabel_handle *rec)
free(spec_arr);

free(data);
rec->data = NULL;
}

static struct selabel_lookup_rec *lookup(struct selabel_handle *rec,
Expand Down
1 change: 1 addition & 0 deletions libselinux/src/label_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static void close(struct selabel_handle *rec)
free(spec_arr);

free(data);
rec->data = NULL;
}

static struct selabel_lookup_rec *lookup(struct selabel_handle *rec,
Expand Down

0 comments on commit f398662

Please sign in to comment.