You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by bu...@bugzilla.spamassassin.org on 2007/01/01 11:59:30 UTC

[Bug 5263] New: getopt does not properly handle missing optional argument in last long option of command line

http://issues.apache.org/SpamAssassin/show_bug.cgi?id=5263

           Summary: getopt does not properly handle missing optional
                    argument in last long option of command line
           Product: Spamassassin
           Version: SVN Trunk (Latest Devel Version)
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P5
         Component: spamc/spamd
        AssignedTo: dev@spamassassin.apache.org
        ReportedBy: sidney@sidney.com


The homegrown getopt_long that we have in spamc/getopt.c has a logic error when
a long option is defined as taking an optional argument and that option is the
last one specified on the command line and has no argument. In that case,
instead of NULL, the argument of the previous option is returned as its argument.

Since spamc does not have any optional argument options this has not caused a
bug so far. I discovered it when trying to add an optional argument to the --ssl
option. For example, if --ssl is redefined to take an optional argument, then 

  spamc --ssl -p 1783

would be parsed as --ssl having no argument (spamc_optarg == NULL) but

  spamc -p 1783 --ssl

as the entire command line would be parsed with spamc_optarg being "1783"

I'm attaching a patch that fixes this.



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 5263] getopt does not properly handle missing optional argument in last long option of command line

Posted by bu...@bugzilla.spamassassin.org.
http://issues.apache.org/SpamAssassin/show_bug.cgi?id=5263


sidney@sidney.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From sidney@sidney.com  2007-01-01 07:19 -------
Committed revision 491585.




------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 5263] getopt does not properly handle missing optional argument in last long option of command line

Posted by bu...@bugzilla.spamassassin.org.
http://issues.apache.org/SpamAssassin/show_bug.cgi?id=5263





------- Additional Comments From sidney@sidney.com  2007-01-01 07:17 -------
Created an attachment (id=3805)
 --> (http://issues.apache.org/SpamAssassin/attachment.cgi?id=3805&action=view)
patch to fix the bug

This patch initializes spamc_optarg to NULL at the beginning of the function
instead of having to do it in multiple execution paths later and possibly
missing one as was the cause of this bug.

I also found a fencepost error processing a longopt at the end of the command
line.




------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.