diff options
author | Stephen Smalley <sds@tycho.nsa.gov> | 2015-08-04 13:56:57 -0400 |
---|---|---|
committer | Stephen Smalley <sds@tycho.nsa.gov> | 2015-08-05 13:03:36 -0400 |
commit | 09ea624d1231798dddfbb32321628424e0ea30e1 (patch) | |
tree | c3a72d166ff8f15c8dec87d8f9a534505edd38f6 /libselinux/src/label_file.c | |
parent | 0454b7ac2c5d24b9c2ad69eacd483dddcd67cb31 (diff) | |
download | android_external_selinux-09ea624d1231798dddfbb32321628424e0ea30e1.tar.gz android_external_selinux-09ea624d1231798dddfbb32321628424e0ea30e1.tar.bz2 android_external_selinux-09ea624d1231798dddfbb32321628424e0ea30e1.zip |
libselinux: support specifying file_contexts.bin file path
At present, the label_file backend expects to be provided the path
to the text file_contexts file and always appends the .bin suffix
when checking for the binary file_contexts.bin file. If one
attempts to directly specify the path to a file_contexts.bin file
to selabel_open(), it will fail as the code will append a second
.bin suffix to it. Check to see if the file path already has a .bin
suffix and do not append it in that case.
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 | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 32525238..b6589681 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -111,9 +111,16 @@ static int load_mmap(struct selabel_handle *rec, const char *path, uint32_t i, magic, version; uint32_t entry_len, stem_map_len, regex_array_len; - rc = snprintf(mmap_path, sizeof(mmap_path), "%s.bin", path); - if (rc >= (int)sizeof(mmap_path)) - return -1; + len = strlen(path); + if (len > 4 && !strcmp(&path[len-4], ".bin")) { + if (len >= sizeof(mmap_path)) + return -1; + strcpy(mmap_path, path); + } else { + rc = snprintf(mmap_path, sizeof(mmap_path), "%s.bin", path); + if (rc >= (int)sizeof(mmap_path)) + return -1; + } mmapfd = open(mmap_path, O_RDONLY | O_CLOEXEC); if (mmapfd < 0) |