Oops. Lost a 'nitems()' chunk during last commit. Don't
authorkrw <krw@openbsd.org>
Thu, 12 Aug 2021 17:30:52 +0000 (17:30 +0000)
committerkrw <krw@openbsd.org>
Thu, 12 Aug 2021 17:30:52 +0000 (17:30 +0000)
segfault on invalid edit commands.

sbin/fdisk/user.c

index 3ea302e..5a9c49a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: user.c,v 1.71 2021/08/12 12:31:16 krw Exp $   */
+/*     $OpenBSD: user.c,v 1.72 2021/08/12 17:30:52 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -100,7 +100,7 @@ again:
                if (!strcmp(cmd, "?"))
                        i = 0;
 
-               if ((cmd_table[i].cmd_name == NULL) || (letoh64(gh.gh_sig) ==
+               if (i >= nitems(cmd_table) || (letoh64(gh.gh_sig) ==
                    GPTSIGNATURE && cmd_table[i].cmd_gpt == 0)) {
                        printf("Invalid command '%s'.  Try 'help'.\n", cmd);
                        continue;