Skip to content

Commit

Permalink
modif: clarify error messages in profile.c
Browse files Browse the repository at this point in the history
  • Loading branch information
kmk3 committed Jan 10, 2025
1 parent 92137f8 commit e60694b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,12 +1617,12 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
arg_rlimit_nofile = 1;
}
else if (strncmp(ptr, "rlimit-cpu ", 11) == 0) {
check_unsigned(ptr + 11, "Error: invalid rlimit in profile file: ");
check_unsigned(ptr + 11, "Error: invalid rlimit-cpu in profile file: ");
sscanf(ptr + 11, "%llu", &cfg.rlimit_cpu);
arg_rlimit_cpu = 1;
}
else if (strncmp(ptr, "rlimit-nproc ", 13) == 0) {
check_unsigned(ptr + 13, "Error: invalid rlimit in profile file: ");
check_unsigned(ptr + 13, "Error: invalid rlimit-nproc in profile file: ");
sscanf(ptr + 13, "%llu", &cfg.rlimit_nproc);
arg_rlimit_nproc = 1;
}
Expand All @@ -1635,7 +1635,7 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
arg_rlimit_fsize = 1;
}
else if (strncmp(ptr, "rlimit-sigpending ", 18) == 0) {
check_unsigned(ptr + 18, "Error: invalid rlimit in profile file: ");
check_unsigned(ptr + 18, "Error: invalid rlimit-sigpending in profile file: ");
sscanf(ptr + 18, "%llu", &cfg.rlimit_sigpending);
arg_rlimit_sigpending = 1;
}
Expand Down Expand Up @@ -1795,18 +1795,24 @@ void profile_read(const char *fname) {
// check file
invalid_filename(fname, 0); // no globbing
if (strlen(fname) == 0 || is_dir(fname)) {
fprintf(stderr, "Error: invalid profile file\n");
fprintf(stderr, "Error: invalid profile file '%s'\n", fname);
exit(1);
}
if (access(fname, R_OK)) {
int errsv = errno;
// if the file ends in ".local", do not exit
const char *base = gnu_basename(fname);
char *ptr = strstr(base, ".local");
if (ptr && strlen(ptr) == 6 && errsv != EACCES)
if (ptr && strlen(ptr) == 6 && errsv != EACCES) {
if (arg_debug) {
printf("Cannot access .local file %s: %s, skipping...\n",
fname, strerror(errsv));
}
return;
}

fprintf(stderr, "Error: cannot access profile file: %s\n", fname);
fprintf(stderr, "Error: cannot access profile file %s: %s\n",
fname, strerror(errsv));
exit(1);
}

Expand All @@ -1832,7 +1838,8 @@ void profile_read(const char *fname) {
// open profile file:
FILE *fp = fopen(fname, "re");
if (fp == NULL) {
fprintf(stderr, "Error: cannot open profile file %s\n", fname);
fprintf(stderr, "Error: cannot open profile file %s: %s\n",
fname, strerror(errno));
exit(1);
}

Expand Down

0 comments on commit e60694b

Please sign in to comment.