Bug 7675

Summary: The -D/--debug option is mis-parsed in sa-learn, spamassassin, and possibly other scripts.
Product: Spamassassin Reporter: Bill Cole <billcole>
Component: spamassassinAssignee: SpamAssassin Developer Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major CC: sidney, wolfsplat
Priority: P2    
Version: unspecified   
Target Milestone: 4.0.0   
Hardware: All   
OS: All   
Whiteboard:

Description Bill Cole 2019-01-02 20:19:56 UTC
There is a logical error/pitfall in parsing the -D/--debug argument in AT LEAST the spamassassin and sa-learn scripts which needs to be either fixed or documented. If you do not follow the option with a list of debug channels, another option, or '--' (indicating the end of options,) it MUST be the last token on the command line. If there is one or more pathnames after --debug, the first will be interpreted as a debug channel. I do not see exactly how this could lead 

Conversely, the documentation for sa-learn does not actually cover the use case of feeding the messages to be learned to sa-learn via STDIN, although that does work. 

For 3.4.3 I think the best approach is to document that -D/--debug MUST have an argument rather than saying it defaults to 'all' when in fact that does not work in the sa-learn or spamassassin scripts if it is at all possible to interpret the following command line token as a channel. It could be disruptive in the terminal 3.x release to change the behavior, even if the existing behavior is arguably a bug. 

For 4.x we need to fix the behavior. Either remove the botched 'default to all' implementation which is inconsistent with the implementation of an extensible set of arbitrarily-named debug channels or fix the Getopt::Long-based command line parser to detect when the token after -D/--debug is a pathname.

I ran across this while investigating bug 7674, which may or may not be related.
Comment 1 Sidney Markowitz 2022-04-16 10:14:46 UTC
It is not possible to distinguish between a pathname and a debug area name. There could be a file in the current directory whose name is a debug area name, making it truly ambiguous. The two solutions I see are to either 1) document in the perldoc description of -D that when it is the last option on the command line before a path, to specify all areas use either -- '' or 'all'  or 2) make the area argument to -D not optional.

I don't like the second alternative because it will break what people are used to and may have put in scripts. Note that, for example spamassassin -D -L ... silently changes behavior because when the argument to -D is not optional '-L' is not recognized as a new option and unknown debug areas silently do nothing. The first alternative seems good enough, and that makes it just a documentation change.
Comment 2 Sidney Markowitz 2022-04-16 23:12:13 UTC
Committed revision 1899918.

Documentation change