aboutsummaryrefslogtreecommitdiff
path: root/src/xz/args.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-07-10 11:33:21 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-07-10 11:33:21 +0300
commiteed9953732b801f6c97317fb3160445a8754180b (patch)
treed528c6afde44a33d667e5d437e083b36003fafc8 /src/xz/args.c
parentUpdated THANKS. (diff)
downloadxz-eed9953732b801f6c97317fb3160445a8754180b.tar.xz
Look for full command names instead of substrings
like "un", "cat", and "lz" when determining if xz is run as unxz, xzcat, lzma, unlzma, or lzcat. This is to ensure that if xz is renamed (e.g. via --program-transform-name), it doesn't so easily work in wrong mode.
Diffstat (limited to '')
-rw-r--r--src/xz/args.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/xz/args.c b/src/xz/args.c
index 97b22448..8d5d33c2 100644
--- a/src/xz/args.c
+++ b/src/xz/args.c
@@ -465,19 +465,23 @@ args_parse(args_info *args, int argc, char **argv)
// NOTE: It's possible that name[0] is now '\0' if argv[0]
// is weird, but it doesn't matter here.
- // If the command name contains "lz",
- // it implies --format=lzma.
- if (strstr(name, "lz") != NULL)
+ // Look for full command names instead of substrings like
+ // "un", "cat", and "lz" to reduce possibility of false
+ // positives when the programs have been renamed.
+ if (strstr(name, "xzcat") != NULL) {
+ opt_mode = MODE_DECOMPRESS;
+ opt_stdout = true;
+ } else if (strstr(name, "unxz") != NULL) {
+ opt_mode = MODE_DECOMPRESS;
+ } else if (strstr(name, "lzcat") != NULL) {
opt_format = FORMAT_LZMA;
-
- // Operation mode
- if (strstr(name, "cat") != NULL) {
- // Imply --decompress --stdout
opt_mode = MODE_DECOMPRESS;
opt_stdout = true;
- } else if (strstr(name, "un") != NULL) {
- // Imply --decompress
+ } else if (strstr(name, "unlzma") != NULL) {
+ opt_format = FORMAT_LZMA;
opt_mode = MODE_DECOMPRESS;
+ } else if (strstr(name, "lzma") != NULL) {
+ opt_format = FORMAT_LZMA;
}
}