diff options
author | Stephen Smalley <sds@tycho.nsa.gov> | 2016-08-17 14:52:00 -0400 |
---|---|---|
committer | Stephen Smalley <sds@tycho.nsa.gov> | 2016-08-17 15:05:48 -0400 |
commit | 6e2bdb770f6311060b111e87bd7af653e225be9d (patch) | |
tree | bf1bd28159223d26d0282e3693552f06296c3118 /libselinux/src/label_file.c | |
parent | dbc6d6d5966508040f59974f77bb8ede5f908d24 (diff) | |
download | android_external_selinux-6e2bdb770f6311060b111e87bd7af653e225be9d.tar.gz android_external_selinux-6e2bdb770f6311060b111e87bd7af653e225be9d.tar.bz2 android_external_selinux-6e2bdb770f6311060b111e87bd7af653e225be9d.zip |
libselinux, sefcontext_compile: handle NULL pcre study data
pcre_study() can return a NULL result if no additional information
could be determined for the pattern. Thus, sefcontext_compile
needs to correctly handle the case where the study data is NULL
when generating file_contexts.bin, and libselinux needs to correctly
handle it when loading file_contexts.bin. Fix them both.
This change enables:
semanage fcontext -a -t httpd_exec_t "(/.*)?"
to succeed, since the regex itself is valid but there is no
additional information produced by pcre_study().
Reported-by: Vit Mojzis <vmojzis@redhat.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Diffstat (limited to 'libselinux/src/label_file.c')
-rw-r--r-- | libselinux/src/label_file.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 071d9020..c89bb35b 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -388,18 +388,21 @@ static int load_mmap(struct selabel_handle *rec, const char *path, rc = -1; goto err; } - spec->lsd.study_data = (void *)mmap_area->next_addr; - spec->lsd.flags |= PCRE_EXTRA_STUDY_DATA; - rc = next_entry(NULL, mmap_area, entry_len); - if (rc < 0) - goto err; - /* Check that study data lengths match. */ - rc = pcre_fullinfo(spec->regex, &spec->lsd, - PCRE_INFO_STUDYSIZE, &len); - if (rc < 0 || len != entry_len) { - rc = -1; - goto err; + if (entry_len) { + spec->lsd.study_data = (void *)mmap_area->next_addr; + spec->lsd.flags |= PCRE_EXTRA_STUDY_DATA; + rc = next_entry(NULL, mmap_area, entry_len); + if (rc < 0) + goto err; + + /* Check that study data lengths match. */ + rc = pcre_fullinfo(spec->regex, &spec->lsd, + PCRE_INFO_STUDYSIZE, &len); + if (rc < 0 || len != entry_len) { + rc = -1; + goto err; + } } data->nspec++; |