aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar smitsohu <smitsohu@gmail.com>2021-03-11 00:31:20 +0100
committerLibravatar smitsohu <smitsohu@gmail.com>2021-03-11 00:31:20 +0100
commit86daaa976b3efc12b1c47a988637dd0633f6d562 (patch)
treefac1979cf679d9c19dfde45fcdc889a6c2227476 /src
parentMerge pull request #4068 from pirate486743186/patch-9 (diff)
downloadfirejail-86daaa976b3efc12b1c47a988637dd0633f6d562.tar.gz
firejail-86daaa976b3efc12b1c47a988637dd0633f6d562.tar.zst
firejail-86daaa976b3efc12b1c47a988637dd0633f6d562.zip
simplify is_link function
Diffstat (limited to 'src')
-rw-r--r--src/firejail/util.c29
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
446int is_link(const char *fname) { 445int 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