From: hanjinpeng Date: Sun, 2 Aug 2026 16:41:11 +0000 (-0400) Subject: ipcmk: do not print a bogus errno for an unparsable --mode X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7cc1de02b2aac83ae6b383aed76a1cb20f5708e;p=thirdparty%2Futil-linux.git ipcmk: do not print a bogus errno for an unparsable --mode The --mode option is the only one in ipcmk(1) that parses its argument by hand instead of using the strutils helpers, and it reports the failure with err(), which appends strerror(errno). strtoul() only sets errno on overflow, so for a malformed argument errno is still 0 and the user gets: $ ipcmk --queue --mode abc ipcmk: failed to parse mode: Success Use str2unum_or_err(), like the other options in this file already do. It picks err()/errx() based on errno and prints the offending string: $ ipcmk --queue --mode abc ipcmk: failed to parse mode: 'abc' $ ipcmk --queue --mode 100000 ipcmk: failed to parse mode: '100000': Numerical result out of range The 07777 upper bound is the range of the mode bits that the resource creation calls accept; values above it were silently truncated to int before. --- diff --git a/sys-utils/ipcmk.c b/sys-utils/ipcmk.c index b8afdd03f..08e7cff5e 100644 --- a/sys-utils/ipcmk.c +++ b/sys-utils/ipcmk.c @@ -228,14 +228,9 @@ int main(int argc, char **argv) ask_psem = 1; break; case 'p': - { - char *end = NULL; - errno = 0; - permission = strtoul(optarg, &end, 8); - if (errno || optarg == end || (end && *end)) - err(EXIT_FAILURE, _("failed to parse mode")); + permission = (mode_t) str2unum_or_err(optarg, 8, + _("failed to parse mode"), 07777); break; - } case 'n': name = optarg; break;