aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar smitsohu <smitsohu@gmail.com>2021-01-08 21:21:25 +0100
committerLibravatar smitsohu <smitsohu@gmail.com>2021-01-08 21:21:51 +0100
commitc00f99f3f6ffd34f83b074da7ed05ff06d4a95c3 (patch)
tree44fb998fc6f2471c00485721b4bf25cf3f3c27b6
parentelectron redirect fixes (#3875) (diff)
downloadfirejail-c00f99f3f6ffd34f83b074da7ed05ff06d4a95c3.tar.gz
firejail-c00f99f3f6ffd34f83b074da7ed05ff06d4a95c3.tar.zst
firejail-c00f99f3f6ffd34f83b074da7ed05ff06d4a95c3.zip
simplify clean_pathname function
-rw-r--r--src/firejail/util.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c
index a3927cc88..6cac535db 100644
--- a/src/firejail/util.c
+++ b/src/firejail/util.c
@@ -565,27 +565,18 @@ char *clean_pathname(const char *path) {
565 if (!rv) 565 if (!rv)
566 errExit("malloc"); 566 errExit("malloc");
567 567
568 if (len > 0) { 568 size_t i = 0;
569 size_t i = 0, j = 0, cnt = 0; 569 size_t j = 0;
570 for (; i < len; i++) { 570 while (path[i]) {
571 if (path[i] == '/') 571 while (path[i] == '/' && path[i+1] == '/')
572 cnt++; 572 i++;
573 else 573 rv[j++] = path[i++];
574 cnt = 0;
575
576 if (cnt < 2) {
577 rv[j] = path[i];
578 j++;
579 }
580 }
581 rv[j] = '\0';
582
583 // remove a trailing slash
584 if (j > 1 && rv[j - 1] == '/')
585 rv[j - 1] = '\0';
586 } 574 }
587 else 575 rv[j] = '\0';
588 *rv = '\0'; 576
577 // remove a trailing slash
578 if (j > 1 && rv[j - 1] == '/')
579 rv[j - 1] = '\0';
589 580
590 return rv; 581 return rv;
591} 582}