aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2018-10-04 07:51:38 -0500
committerLibravatar GitHub <noreply@github.com>2018-10-04 07:51:38 -0500
commit5b40b28eab1b50c6f3d2ba1685c8a2fdf1c98a19 (patch)
treebeaea31cf1ee98343eee888e90f1cb36d7fc308f
parentFixes #2048 (diff)
parentFix command name parsing so that program paths with spaces do not cause the w... (diff)
downloadfirejail-5b40b28eab1b50c6f3d2ba1685c8a2fdf1c98a19.tar.gz
firejail-5b40b28eab1b50c6f3d2ba1685c8a2fdf1c98a19.tar.zst
firejail-5b40b28eab1b50c6f3d2ba1685c8a2fdf1c98a19.zip
Merge pull request #2130 from crass/fix-2045
FIX-2045: Fix command name parsing for program paths with spaces.
-rw-r--r--src/firejail/util.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c
index 4a164901d..ae07a42b0 100644
--- a/src/firejail/util.c
+++ b/src/firejail/util.c
@@ -636,33 +636,33 @@ void extract_command_name(int index, char **argv) {
636 if (!cfg.command_name) 636 if (!cfg.command_name)
637 errExit("strdup"); 637 errExit("strdup");
638 638
639 // restrict the command name to the first word
640 char *ptr = cfg.command_name;
641 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0')
642 ptr++;
643 *ptr = '\0';
644
645 // remove the path: /usr/bin/firefox becomes firefox 639 // remove the path: /usr/bin/firefox becomes firefox
646 ptr = strrchr(cfg.command_name, '/'); 640 char *basename = cfg.command_name;
641 char *ptr = strrchr(cfg.command_name, '/');
647 if (ptr) { 642 if (ptr) {
648 ptr++; 643 basename = ++ptr;
649 if (*ptr == '\0') { 644 if (*ptr == '\0') {
650 fprintf(stderr, "Error: invalid command name\n"); 645 fprintf(stderr, "Error: invalid command name\n");
651 exit(1); 646 exit(1);
652 } 647 }
648 }
649 else
650 ptr = basename;
653 651
654 char *tmp = strdup(ptr); 652 // restrict the command name to the first word
655 if (!tmp) 653 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0')
656 errExit("strdup"); 654 ptr++;
657 655
658 // limit the command to the first ' ' 656 // command name is a substring of cfg.command_name
659 char *ptr2 = tmp; 657 if (basename != cfg.command_name || *ptr != '\0') {
660 while (*ptr2 != ' ' && *ptr2 != '\0') 658 *ptr = '\0';
661 ptr2++; 659
662 *ptr2 = '\0'; 660 basename = strdup(basename);
661 if (!basename)
662 errExit("strdup");
663 663
664 free(cfg.command_name); 664 free(cfg.command_name);
665 cfg.command_name = tmp; 665 cfg.command_name = basename;
666 } 666 }
667} 667}
668 668