block: validate amount of arguments for the "autofs" command
authorRafał Miłecki <rafal@milecki.pl>
Sun, 9 Dec 2018 13:22:17 +0000 (14:22 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Sun, 9 Dec 2018 13:22:17 +0000 (14:22 +0100)
Using argv[3] without checking argc value could result in undefined
behavior. It could result in a crash or accessing a NULL that separates
argv from envp on UNIX.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
block.c

diff --git a/block.c b/block.c
index 46050b4f3f7c38fde1933ad4478ea183abd0c46b..a0bbf47aa780a865be1db96dc242564244f040c3 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1157,6 +1157,10 @@ static int main_autofs(int argc, char **argv)
                }
                return 0;
        }
+
+       if (argc < 4)
+               return -EINVAL;
+
        return mount_action(argv[2], argv[3], TYPE_AUTOFS);
 }