]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ipcs: check errno after strto..()
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 13:00:40 +0000 (15:00 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Jul 2021 09:33:27 +0000 (11:33 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/ipcmk.c
sys-utils/ipcrm.c

index 0a84be77e50fa533692e74f8ac02db5d1d1ca633..d6e5ce6c982a02c4f0d3ac526c24ee9e02466471 100644 (file)
@@ -122,9 +122,14 @@ int main(int argc, char **argv)
                        ask_sem = 1;
                        break;
                case 'p':
+               {
+                       char *end = NULL;
+                       errno = 0;
                        permission = strtoul(optarg, NULL, 8);
+                       if (errno || optarg == end || (end && *end))
+                               err(EXIT_FAILURE, _("failed to parse mode"));
                        break;
-
+               }
                case 'h':
                        usage();
                case 'V':
index 5a27b7d2099e7654689983f31d82f5d24c48414a..52768a242971313ec8e67ea1f7e53e418f6ea732 100644 (file)
@@ -125,12 +125,13 @@ static int remove_id(int type, int iskey, int id)
 static int remove_arg_list(type_id type, int argc, char **argv)
 {
        int id;
-       char *end;
+       char *end = NULL;
        int nb_errors = 0;
 
        do {
+               errno = 0;
                id = strtoul(argv[0], &end, 10);
-               if (*end != 0) {
+               if (errno || !end || *end != 0) {
                        warnx(_("invalid id: %s"), argv[0]);
                        nb_errors++;
                } else {