Skip to content

Commit

Permalink
secilc: better error handling
Browse files Browse the repository at this point in the history
Fix a situation where the secilc command line tool could return success
even though the compilation failed.

  $ secilc /dev/null -o /dev/null -f /dev/null
  Failure reading file: /dev/null
  $ echo $?
  0

Signed-off-by: Nick Kralevich <[email protected]>
  • Loading branch information
Nick Kralevich via Selinux authored and William Roberts committed Sep 25, 2018
1 parent 0a71c5f commit 2896967
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions secilc/secilc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ int main(int argc, char *argv[])
rc = stat(argv[i], &filedata);
if (rc == -1) {
fprintf(stderr, "Could not stat file: %s\n", argv[i]);
rc = SEPOL_ERR;
goto exit;
}
file_size = filedata.st_size;
Expand All @@ -265,6 +266,7 @@ int main(int argc, char *argv[])
rc = fread(buffer, file_size, 1, file);
if (rc != 1) {
fprintf(stderr, "Failure reading file: %s\n", argv[i]);
rc = SEPOL_ERR;
goto exit;
}
fclose(file);
Expand Down Expand Up @@ -345,11 +347,13 @@ int main(int argc, char *argv[])

if (file_contexts == NULL) {
fprintf(stderr, "Failed to open file_contexts file\n");
rc = SEPOL_ERR;
goto exit;
}

if (fwrite(fc_buf, sizeof(char), fc_size, file_contexts) != fc_size) {
fprintf(stderr, "Failed to write file_contexts file\n");
rc = SEPOL_ERR;
goto exit;
}

Expand Down

0 comments on commit 2896967

Please sign in to comment.