[GH-ISSUE #842] Some bash completion errors #452

Closed
opened 2026-10-14 03:08:29 +07:00 by bsakaguchi · 13 comments
Owner

Originally created by @frank-dittrich on GitHub (Nov 4, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/842

I intend to fix them when I find the time.

1: Markov mode completion

(bleeding-jumbo)run $ grep "^\[Markov:" john*.conf
john.conf:[Markov:Default]
john.local.conf:[Markov:fd]
(bleeding-jumbo)run $ ./john --stdout --markov=[tab][tab]
LEVEL[:START[:END[:LENGTH]]]
MODE
MODE:LEVEL[:START[:END[:LENGTH]]]

The two markov modes, default and fd, should have been listed as possible completions.
Without --stdout, it works:

(bleeding-jumbo)run $ ./john --markov=
LEVEL[:START[:END[:LENGTH]]]
MODE
MODE:LEVEL[:START[:END[:LENGTH]]]
default
fd

2: External mode completion with --config=...

./john --config=fd.conf --external=[tab][tab] lists all external modes defined in fd.conf as possible completions
./john --stdout --config=fd.conf --external=[tab][tab] lists all external modes defined in john.conf instead.

3: bash completion doesn't work with "" or '' on the command line preceding the token to be completed.

./john --mask=?l?l?l --external=[tab][tab] lists all external modes as possible completions.
./john --mask="?l?l?l" --external=[tab][tab] lists all file names as possible completions.
./john --mask='?l?l?l' --external=[tab][tab] lists all file names as possible completions.

That one is possibly harder to fix. I doubt that it is a john.bas_completion bug.
More likely, it is a bug in _get_comp_words_by_ref (used inside john.bash_completion).
Because the same bug can be reproduced like this:

cut --delimiter=" " --fie[tab][tab] doesn't complete --fie to fields, while cut --delimiter=: --fie[tab][tab] does

Can someon check this on othert systems (i.e., not Fefdora 20)?

Workaround: quote like this:
cut "--delimiter= " --fie[tab][tab]

The same workaround also helps for john.bash_completion:
./john "--mask=?l?l?l" --external=[tab][tab] lists all external modes as possible completions.
./john '--mask=?l?l?l' --external=[tab][tab] lists all external modes as possible completions.

Originally created by @frank-dittrich on GitHub (Nov 4, 2014). Original GitHub issue: https://github.com/openwall/john/issues/842 I intend to fix them when I find the time. 1: Markov mode completion ``` (bleeding-jumbo)run $ grep "^\[Markov:" john*.conf john.conf:[Markov:Default] john.local.conf:[Markov:fd] (bleeding-jumbo)run $ ./john --stdout --markov=[tab][tab] LEVEL[:START[:END[:LENGTH]]] MODE MODE:LEVEL[:START[:END[:LENGTH]]] ``` The two markov modes, default and fd, should have been listed as possible completions. Without `--stdout`, it works: ``` (bleeding-jumbo)run $ ./john --markov= LEVEL[:START[:END[:LENGTH]]] MODE MODE:LEVEL[:START[:END[:LENGTH]]] default fd ``` 2: External mode completion with --config=... `./john --config=fd.conf --external=[tab][tab]` lists all external modes defined in fd.conf as possible completions `./john --stdout --config=fd.conf --external=[tab][tab]` lists all external modes defined in john.conf instead. 3: bash completion doesn't work with "" or '' on the command line preceding the token to be completed. `./john --mask=?l?l?l --external=[tab][tab]` lists all external modes as possible completions. `./john --mask="?l?l?l" --external=[tab][tab]` lists all file names as possible completions. `./john --mask='?l?l?l' --external=[tab][tab]` lists all file names as possible completions. That one is possibly harder to fix. I doubt that it is a john.bas_completion bug. More likely, it is a bug in _get_comp_words_by_ref (used inside john.bash_completion). Because the same bug can be reproduced like this: `cut --delimiter=" " --fie[tab][tab]` doesn't complete `--fie` to `fields`, while `cut --delimiter=: --fie[tab][tab]` does Can someon check this on othert systems (i.e., not Fefdora 20)? Workaround: quote like this: `cut "--delimiter= " --fie[tab][tab]` The same workaround also helps for john.bash_completion: `./john "--mask=?l?l?l" --external=[tab][tab]` lists all external modes as possible completions. `./john '--mask=?l?l?l' --external=[tab][tab]` lists all external modes as possible completions.
bsakaguchi 2026-10-14 03:08:29 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@frank-dittrich commented on GitHub (Nov 4, 2014):

I think I found the root cause for 1 and 2:

(bleeding-jumbo)run $ ./john --stdout --list=externals 
Invalid options combination or duplicate option: "--stdout"
(bleeding-jumbo)run $ ./john --stdout --list=markov    
Invalid options combination or duplicate option: "--stdout"
<!-- gh-comment-id:61602194 --> @frank-dittrich commented on GitHub (Nov 4, 2014): I think I found the root cause for 1 and 2: ``` (bleeding-jumbo)run $ ./john --stdout --list=externals Invalid options combination or duplicate option: "--stdout" (bleeding-jumbo)run $ ./john --stdout --list=markov Invalid options combination or duplicate option: "--stdout" ```
Author
Owner

@magnumripper commented on GitHub (Nov 4, 2014):

Hmm but what is the cause for that!? It doesn't make sense. --list uses FLG_ZERO which has its own dupe check: --list is only incompatible with another --list.

<!-- gh-comment-id:61606144 --> @magnumripper commented on GitHub (Nov 4, 2014): Hmm but what is the cause for _that_!? It doesn't make sense. --list uses FLG_ZERO which has its own dupe check: --list is only incompatible with another --list.
Author
Owner

@magnumripper commented on GitHub (Nov 4, 2014):

See 783980c 42a6d94 5aad5860 0b5ce0d52. Did it work before 0b5ce0d52?

<!-- gh-comment-id:61606505 --> @magnumripper commented on GitHub (Nov 4, 2014): See 783980c 42a6d94 5aad5860 0b5ce0d52. Did it work before 0b5ce0d52?
Author
Owner

@frank-dittrich commented on GitHub (Nov 4, 2014):

Hmm but what is the cause for that!?

I guess it is related to

(bleeding-jumbo)run $ ./john --stdout
Invalid options combination or duplicate option: "--stdout"

Probably it is the FLG_BATCH_CHK in

options.c:      {"stdout", FLG_STDOUT, FLG_STDOUT,
options.c-              FLG_CRACKING_SUP, FLG_SINGLE_CHK | FLG_BATCH_CHK,

I tried to avoid that with

(bleeding-jumbo)src $ git diff
diff --git a/src/options.c b/src/options.c
index 9d3c214..c2eaba1 100644
--- a/src/options.c
+++ b/src/options.c
@@ -491,8 +491,7 @@ void opt_init(char *name, int argc, char **argv, int show_usage)
                //else
                        options.flags |= FLG_CRACKING_SET;
        }
-
-       if (!(options.flags & FLG_ACTION))
+       if (options.listconf == NULL && !(options.flags & FLG_ACTION))
                options.flags |= FLG_BATCH_SET;

        opt_check(opt_list, options.flags, argv);

But that didn't help, either.

<!-- gh-comment-id:61606971 --> @frank-dittrich commented on GitHub (Nov 4, 2014): > Hmm but what is the cause for that!? I guess it is related to ``` (bleeding-jumbo)run $ ./john --stdout Invalid options combination or duplicate option: "--stdout" ``` Probably it is the `FLG_BATCH_CHK` in ``` options.c: {"stdout", FLG_STDOUT, FLG_STDOUT, options.c- FLG_CRACKING_SUP, FLG_SINGLE_CHK | FLG_BATCH_CHK, ``` I tried to avoid that with ``` (bleeding-jumbo)src $ git diff diff --git a/src/options.c b/src/options.c index 9d3c214..c2eaba1 100644 --- a/src/options.c +++ b/src/options.c @@ -491,8 +491,7 @@ void opt_init(char *name, int argc, char **argv, int show_usage) //else options.flags |= FLG_CRACKING_SET; } - - if (!(options.flags & FLG_ACTION)) + if (options.listconf == NULL && !(options.flags & FLG_ACTION)) options.flags |= FLG_BATCH_SET; opt_check(opt_list, options.flags, argv); ``` But that didn't help, either.
Author
Owner

@magnumripper commented on GitHub (Nov 4, 2014):

Oh, I see. This is not a bug per se but just a result of the options parsing. We need some kind of workaround similar to what you did.

<!-- gh-comment-id:61681361 --> @magnumripper commented on GitHub (Nov 4, 2014): Oh, I see. This is not a bug per se but just a result of the options parsing. We need some kind of workaround similar to what you did.
Author
Owner

@magnumripper commented on GitHub (Nov 5, 2014):

This works for -stdout but it may cause problems (or just not help) for other combinations.

+   if (options.listconf != NULL)
+       options.flags |= (FLG_CRACKING_SUP | FLG_STDIN_SET);
+
    if (options.listconf == NULL && !(options.flags & FLG_ACTION))
        options.flags |= FLG_BATCH_SET;
<!-- gh-comment-id:61737968 --> @magnumripper commented on GitHub (Nov 5, 2014): This works for -stdout but it may _cause_ problems (or just not help) for other combinations. ``` + if (options.listconf != NULL) + options.flags |= (FLG_CRACKING_SUP | FLG_STDIN_SET); + if (options.listconf == NULL && !(options.flags & FLG_ACTION)) options.flags |= FLG_BATCH_SET; ```
Author
Owner

@magnumripper commented on GitHub (Nov 5, 2014):

It doesn't seem to cause problems though. And ../run/john -stdin -list=markov works too without adding anything more.

<!-- gh-comment-id:61738393 --> @magnumripper commented on GitHub (Nov 5, 2014): It doesn't seem to cause problems though. And `../run/john -stdin -list=markov` works too without adding anything more.
Author
Owner

@magnumripper commented on GitHub (Nov 5, 2014):

BTW if it cause problems, it will only cause problems for --list. So we could commit this without super serious regression testing...

<!-- gh-comment-id:61738496 --> @magnumripper commented on GitHub (Nov 5, 2014): BTW **if** it cause problems, it will only cause problems for --list. So we could commit this without super serious regression testing...
Author
Owner

@frank-dittrich commented on GitHub (Nov 5, 2014):

BTW if it cause problems, it will only cause problems for --list. So we could commit this without super serious regression testing...

Agreed. Please do commit that fix (may be add a comment that othetrwise --stdout --list=... will fail) and close the bug. Thanks for fixing.

<!-- gh-comment-id:61835702 --> @frank-dittrich commented on GitHub (Nov 5, 2014): > BTW <b>if</b> it cause problems, it will only cause problems for --list. So we could commit this without super serious regression testing... Agreed. Please do commit that fix (may be add a comment that othetrwise --stdout --list=... will fail) and close the bug. Thanks for fixing.
Author
Owner

@frank-dittrich commented on GitHub (Nov 11, 2014):

Unfortunately, your fix for --stdout --list=... breaks

$ ./john --fork=3 --list=inc-modes
Invalid options combination or duplicate option: "--fork=3"
<!-- gh-comment-id:62575772 --> @frank-dittrich commented on GitHub (Nov 11, 2014): Unfortunately, your fix for `--stdout --list=...` breaks ``` $ ./john --fork=3 --list=inc-modes Invalid options combination or duplicate option: "--fork=3" ```
Author
Owner

@frank-dittrich commented on GitHub (Nov 11, 2014):

This seems to work:

-       if (options.listconf != NULL)
+       if (options.listconf != NULL && options.fork == NULL)
<!-- gh-comment-id:62576892 --> @frank-dittrich commented on GitHub (Nov 11, 2014): This seems to work: ``` - if (options.listconf != NULL) + if (options.listconf != NULL && options.fork == NULL) ```
Author
Owner

@frank-dittrich commented on GitHub (Nov 11, 2014):

I committed the working fix as 172e933.

<!-- gh-comment-id:62581661 --> @frank-dittrich commented on GitHub (Nov 11, 2014): I committed the working fix as 172e933.
Author
Owner

@magnumripper commented on GitHub (Nov 11, 2014):

👍 there are probably a few more cases yet to be found.

<!-- gh-comment-id:62588757 --> @magnumripper commented on GitHub (Nov 11, 2014): :+1: there are probably a few more cases yet to be found.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#452
No description provided.