From 13eef467bf56e0d9e01718b60a87a262eae6113d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 6 Sep 2019 17:12:52 +0200 Subject: [PATCH] tar2qfile: fix argument parser There is only one input, other arguments are files/directories to extract. There is no need for a loop. --- qubes-rpc/tar2qfile.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/qubes-rpc/tar2qfile.c b/qubes-rpc/tar2qfile.c index b0786d2..c05e130 100644 --- a/qubes-rpc/tar2qfile.c +++ b/qubes-rpc/tar2qfile.c @@ -957,7 +957,6 @@ void tar_file_processor(int fd, struct filters *filters) int main(int argc, char **argv) { - int i; char *entry; int fd = -1; int use_stdin = 1; @@ -967,18 +966,15 @@ int main(int argc, char **argv) /* when extracting backup header, dom0 will terminate the transfer with * EDQUOT just after getting qubes.xml */ set_ignore_quota_error(1); - for (i = 1; i < argc; i++) { - set_nonblock(0); - if (strcmp(argv[i], "-")==0) { + set_nonblock(0); + if (argc > 1) { + if (strcmp(argv[1], "-")==0) { use_stdin = 1; - i++; - break; } else { - // Parse tar file use_stdin = 0; - entry = argv[i]; + entry = argv[1]; #ifdef DEBUG - fprintf(stderr,"Parsing file %s\n",entry); + fprintf(stderr, "Parsing file %s\n",entry); #endif fd = open(entry, O_RDONLY); @@ -986,12 +982,14 @@ int main(int argc, char **argv) fprintf(stderr,"Error opening file %s\n",entry); exit(2); } - i++; - break; } } - filters.filters_count = argc-i; - filters.filters = argv+i; + // Parse tar file + if (argc > 2) + filters.filters_count = argc-2; + else + filters.filters_count = 0; + filters.filters = argv+2; filters.filters_matches = calloc(filters.filters_count, sizeof(int)); if (filters.filters_matches == NULL) { perror("calloc");