Skip to content

Commit 92dceb5

Browse files
committed
modif: improve error messages in mountinfo.c
Relates to #6450.
1 parent 62f477d commit 92dceb5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/firejail/mountinfo.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ static void parse_line(char *line, MountData *output) {
107107
if (output->mountid < 0 ||
108108
output->fsname == NULL ||
109109
output->dir == NULL ||
110-
output->fstype == NULL)
111-
goto errexit;
110+
output->fstype == NULL) {
111+
fprintf(stderr, "Error: invalid MountData from line: '%s': mountid=%d fsname=%s dir=%s fstype=%s\n",
112+
line, output->mountid, output->fsname, output->dir,
113+
output->fstype);
114+
exit(1);
115+
}
112116

113117
// restore empty spaces
114118
unmangle_path(output->fsname);
@@ -117,7 +121,7 @@ static void parse_line(char *line, MountData *output) {
117121
return;
118122

119123
errexit:
120-
fprintf(stderr, "Error: cannot read /proc/self/mountinfo\n");
124+
fprintf(stderr, "Error: cannot parse line from /proc/self/mountinfo: '%s'\n", line);
121125
exit(1);
122126
}
123127

@@ -127,7 +131,7 @@ MountData *get_last_mount(void) {
127131
FILE *fp = fopen("/proc/self/mountinfo", "re");
128132
if (!fp) {
129133
fprintf(stderr, "Error: cannot read /proc/self/mountinfo\n");
130-
exit(1);
134+
errExit("fopen");
131135
}
132136

133137
mbuf[0] = '\0';
@@ -158,8 +162,8 @@ static int get_mount_id_from_handle(int fd) {
158162
int rv = -1;
159163
int tmp;
160164
if (name_to_handle_at(-1, proc, fh, &tmp, AT_SYMLINK_FOLLOW) != -1) {
161-
fprintf(stderr, "Error: unexpected result from name_to_handle_at\n");
162-
exit(1);
165+
fprintf(stderr, "Error: unexpected result from name_to_handle_at for fd %d\n", fd);
166+
errExit("name_to_handle_at");
163167
}
164168
if (errno == EOVERFLOW && fh->handle_bytes)
165169
rv = tmp;
@@ -184,8 +188,8 @@ static int get_mount_id_from_fdinfo(int fd) {
184188

185189
FILE *fp = fopen(proc, "re");
186190
if (!fp) {
187-
fprintf(stderr, "Error: cannot read proc file\n");
188-
exit(1);
191+
fprintf(stderr, "Error: cannot read %s\n", proc);
192+
errExit("fopen");
189193
}
190194

191195
if (called_as_root == 0)
@@ -218,7 +222,7 @@ char **build_mount_array(const int mountid, const char *path) {
218222
FILE *fp = fopen("/proc/self/mountinfo", "re");
219223
if (!fp) {
220224
fprintf(stderr, "Error: cannot read /proc/self/mountinfo\n");
221-
exit(1);
225+
errExit("fopen");
222226
}
223227

224228
// try to find line with mount id

0 commit comments

Comments
 (0)