https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7155
--- Comment #1 from Karsten Bräckelmann <[email protected]> --- The problem is in getopt.c spamc_getopt_long(). In its for(i) loop, it compares the given long option to the array of valid options (as defined in the spamc.c longoptions[] array). It does so using memcmp() limited to the length of the given option (without the option's trailing "=value", if given). The option is compared against the array of valid longoptions in the order specified, so its order actually matters for options that are prefix substrings of other options. That means, a given "foo" option compares successfully to either "foo" or "foo-bar", whichever is defined first, since we're only comparing the first 3 bytes in this example. (This does not apply to options merely sharing a common prefix like connect-timeout and connect-retries.) As for this bug, the option "full" matches the first 4 chars of "full-spam", which is defined before "full" in the longoptions[] array, thus falsely being handled as the "full-spam" or -r option. A quick-n-dirty fix is to reverse the order of the "full" and "full-spam" entries on the spamc.c longoptions[] array: { "full", no_argument, 0, 'R' }, /* substring prefix first */ { "full-spam", no_argument, 0, 'r' }, Minimally intrusive, but only working around this one issue, not fixing the underlying problem. Using e.g. strcmp() instead of memcmp() unfortunately is not a simple drop-in replacement, because the user given option string includes a "=value" suffix if given. Hence the need for a length limited match in the first place. The committed fix requires the length of the given option name to be equal to the length of the compared-to option name in addition to the existing memcmp(). Sending spamc/getopt.c Committed revision 1802715. This should be a minimally intrusive fix. Not extensively tested, though, so please review -- especially if your C is better than mine. ;) Patch applies cleanly to 3.4 branch. Should be safe for both branches. -- You are receiving this mail because: You are the assignee for the bug.
