libselinux: do not treat an empty file_contexts(.local) as an error

file_contexts can be legitimately empty, particularly when dealing with
a file_contexts.local file.  The change to test for file_contexts.bin
format by magic number was treating an EOF condition as a fatal error,
thereby causing an error on empty file_contexts.local files.  Only
treat it as an error if there was truly an error on the read, as
checked via ferror().  Otherwise, clear the error and EOF indicators
so that they do not persist when we rewind the file and try to read
it as text.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
This commit is contained in:
Stephen Smalley 2015-08-07 10:02:35 -04:00
parent 3e46f3199e
commit 8a9d25a8e9
1 changed files with 7 additions and 3 deletions

View File

@ -447,11 +447,15 @@ static int process_file(const char *path, const char *suffix,
return -1;
}
magic = 0;
if (fread(&magic, sizeof magic, 1, fp) != 1) {
if (ferror(fp)) {
errno = EINVAL;
fclose(fp);
return -1;
}
clearerr(fp);
}
if (magic == SELINUX_MAGIC_COMPILED_FCONTEXT) {
/* file_contexts.bin format */