#1122571 psmisc: Segmentation fault due to harmlessly stacked option parms

Package:
psmisc
Source:
psmisc
Description:
utilities that use the proc file system
Submitter:
Oliver M. Schode
Date:
2025-12-12 09:59:07 UTC
Severity:
normal
Tags:
#1122571#5
Date:
2025-12-11 12:56:42 UTC
From:
To:
Dear Maintainer,

merely running

$ killall -vV

results in segmentation fault. I didn't try many other combinations
after hitting on this accidentally, consider others may abort as well.
Stacking "old style" options certainly works, even where otherwise
meaningless, such as

$ killall -vl

but the segfault should not happen in any case.


Regards,
Oliver

#1122571#10
Date:
2025-12-12 08:28:52 UTC
From:
To:
Hi Oliver,
  How strange, I can see it here too.
Have you been able to make it happen for anything except where the first
character is a valid option and the second is capital V?
 - Craig

#1122571#15
Date:
2025-12-12 09:43:41 UTC
From:
To:
Hi Craig,

thanks for the quick feedback. I could not reproduce with any other
combination and suspected it must be due to that specific parameter's
positional handling. I've had a look now and sure enough, it's a
classic:

https://github.com/acg/psmisc/blob/master/src/killall.c#L824C1-L829C8

case 'V':
 /* option check is optind-1 but sig name is optind */
 if (strcmp(argv[optind-1],"-V") == 0 || strncmp(argv[optind-1],"--",2) == 0) {
    print_version();
    return 0;
 }

The second strncmp does it since at this time and with the given opt
string, getopt would have advanced its internal pointer. Assuming
argv[optind-1] still holds the token is generally the wrong approach to
sort out whether short or long option is present.

- Oliver