summaryrefslogtreecommitdiff
path: root/ubi-utils
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-09-21 14:18:04 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-11-03 19:41:32 +0100
commit3c54e4e46c2248ed9143c2f07670307185719331 (patch)
tree8f11ba5fb74b1ca38e5b78b52a270dda02e594d5 /ubi-utils
parentce50e6d8d15b384ebf7021865a95d6f18d191291 (diff)
ubi-utils: ubicrc32: process command line arguments first
When a command line option is used (e.g. --version), the tool tries to open it as a file first, then *uppon success* attempts to process the command line options (including what it assumed to be an input file) which is obviously broken. This patch moves command line processing first and then attempts to open *the first unprocessed* argument. Reported-by: Uwe Kleine-König <ukleinek@debian.org> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubi-utils')
-rw-r--r--ubi-utils/ubicrc32.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/ubi-utils/ubicrc32.c b/ubi-utils/ubicrc32.c
index 0ea255d..885f348 100644
--- a/ubi-utils/ubicrc32.c
+++ b/ubi-utils/ubicrc32.c
@@ -89,19 +89,18 @@ int main(int argc, char * const argv[])
int err = 0;
uint32_t crc = UBI_CRC32_INIT;
char buf[BUFSIZE];
- FILE *fp;
-
- if (argc > 1) {
- fp = fopen(argv[1], "r");
- if (!fp)
- return sys_errmsg("cannot open \"%s\"", argv[1]);
- } else
- fp = stdin;
+ FILE *fp = stdin;
err = parse_opt(argc, argv);
if (err)
return err;
+ if (optind < argc) {
+ fp = fopen(argv[optind], "r");
+ if (!fp)
+ return sys_errmsg("cannot open \"%s\"", argv[1]);
+ }
+
while (!feof(fp)) {
size_t read;