diff options
-rw-r--r-- | src/firejail/util.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c index 53c671794..2ad85acd6 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -441,35 +441,22 @@ int is_dir(const char *fname) { | |||
441 | return 0; | 441 | return 0; |
442 | } | 442 | } |
443 | 443 | ||
444 | |||
445 | // return 1 if the file is a link | 444 | // return 1 if the file is a link |
446 | int is_link(const char *fname) { | 445 | int is_link(const char *fname) { |
447 | assert(fname); | 446 | assert(fname); |
448 | if (*fname == '\0') | 447 | if (*fname == '\0') |
449 | return 0; | 448 | return 0; |
450 | 449 | ||
451 | char *dup = NULL; | 450 | char *dup = strdup(fname); |
452 | struct stat s; | 451 | if (!dup) |
453 | if (lstat(fname, &s) == 0) { | 452 | errExit("strdup"); |
454 | if (S_ISLNK(s.st_mode)) | 453 | trim_trailing_slash_or_dot(dup); |
455 | return 1; | 454 | |
456 | if (S_ISDIR(s.st_mode)) { | 455 | char c; |
457 | // remove trailing slashes and single dots and try again | 456 | ssize_t rv = readlink(dup, &c, 1); |
458 | dup = strdup(fname); | ||
459 | if (!dup) | ||
460 | errExit("strdup"); | ||
461 | trim_trailing_slash_or_dot(dup); | ||
462 | if (lstat(dup, &s) == 0) { | ||
463 | if (S_ISLNK(s.st_mode)) { | ||
464 | free(dup); | ||
465 | return 1; | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | 457 | ||
471 | free(dup); | 458 | free(dup); |
472 | return 0; | 459 | return (rv != -1); |
473 | } | 460 | } |
474 | 461 | ||
475 | // remove all slashes and single dots from the end of a path | 462 | // remove all slashes and single dots from the end of a path |