]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ipcmk: do not print a bogus errno for an unparsable --mode
authorhanjinpeng <hanjinpeng@kylinos.cn>
Sun, 2 Aug 2026 16:41:11 +0000 (12:41 -0400)
committerhanjinpeng <hanjinpeng@kylinos.cn>
Mon, 3 Aug 2026 12:36:47 +0000 (08:36 -0400)
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.

sys-utils/ipcmk.c

index b8afdd03f269706e778a2715e6538612806346e3..08e7cff5e337cc1daceeb5ede6a6cf3442a018ae 100644 (file)
@@ -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;