aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/ls.c')
-rw-r--r--src/firejail/ls.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/firejail/ls.c b/src/firejail/ls.c
index 86c3a6079..5444ad9c2 100644
--- a/src/firejail/ls.c
+++ b/src/firejail/ls.c
@@ -258,42 +258,35 @@ void sandboxfs(int op, pid_t pid, const char *path1, const char *path2) {
258 // drop privileges 258 // drop privileges
259 drop_privs(0); 259 drop_privs(0);
260 260
261 // check access
261 if (access(fname1, R_OK) == -1) { 262 if (access(fname1, R_OK) == -1) {
262 fprintf(stderr, "Error: Cannot access %s\n", fname1); 263 fprintf(stderr, "Error: Cannot access %s\n", fname1);
263 exit(1); 264 exit(1);
264 } 265 }
266 char *rp = realpath(fname1, NULL);
267 if (!rp) {
268 fprintf(stderr, "Error: Cannot access %s\n", fname1);
269 exit(1);
270 }
271 if (arg_debug)
272 printf("realpath %s\n", rp);
273
265 274
266 // list directory contents 275 // list directory contents
267 struct stat s; 276 struct stat s;
268 if (stat(fname1, &s) == -1) { 277 if (stat(rp, &s) == -1) {
269 fprintf(stderr, "Error: Cannot access %s\n", fname1); 278 fprintf(stderr, "Error: Cannot access %s\n", rp);
270 exit(1); 279 exit(1);
271 } 280 }
272 if (S_ISDIR(s.st_mode)) { 281 if (S_ISDIR(s.st_mode)) {
273 char *rp = realpath(fname1, NULL);
274 if (!rp) {
275 fprintf(stderr, "Error: Cannot access %s\n", fname1);
276 exit(1);
277 }
278 if (arg_debug)
279 printf("realpath %s\n", rp);
280
281 char *dir; 282 char *dir;
282 if (asprintf(&dir, "%s/", rp) == -1) 283 if (asprintf(&dir, "%s/", rp) == -1)
283 errExit("asprintf"); 284 errExit("asprintf");
284 285
285 print_directory(dir); 286 print_directory(dir);
286 free(rp);
287 free(dir); 287 free(dir);
288 } 288 }
289 else { 289 else {
290 char *rp = realpath(fname1, NULL);
291 if (!rp) {
292 fprintf(stderr, "Error: Cannot access %s\n", fname1);
293 exit(1);
294 }
295 if (arg_debug)
296 printf("realpath %s\n", rp);
297 char *split = strrchr(rp, '/'); 290 char *split = strrchr(rp, '/');
298 if (split) { 291 if (split) {
299 *split = '\0'; 292 *split = '\0';
@@ -302,8 +295,8 @@ void sandboxfs(int op, pid_t pid, const char *path1, const char *path2) {
302 printf("path %s, file %s\n", rp, rp2); 295 printf("path %s, file %s\n", rp, rp2);
303 print_file_or_dir(rp, rp2, 1); 296 print_file_or_dir(rp, rp2, 1);
304 } 297 }
305 free(rp);
306 } 298 }
299 free(rp);
307 } 300 }
308 301
309 // get file from sandbox and store it in the current directory 302 // get file from sandbox and store it in the current directory