From: Jim Meyering Date: Mon, 21 Jun 2004 15:35:12 +0000 (+0000) Subject: (main): Don't segfault when calculating the X-Git-Tag: v5.3.0~1284 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f53347b996942a516b5039b18d8df1a1ff4ed37e;p=thirdparty%2Fcoreutils.git (main): Don't segfault when calculating the expected number of operands for `mknod NAME'. --- diff --git a/src/mknod.c b/src/mknod.c index 58f12f9b22..a3a9d2270b 100644 --- a/src/mknod.c +++ b/src/mknod.c @@ -132,7 +132,12 @@ main (int argc, char **argv) newmode = mode_adjust (newmode, change); } - expected_operands = (argv[optind + 1][0] == 'p' ? 2 : 4); + /* If the number of arguments is 0 or 1, + or (if it's 2 or more and the second one starts with `p'), then there + must be exactly two operands. Otherwise, there must be four. */ + expected_operands = (argc <= optind + || (optind + 1 < argc && argv[optind + 1][0] == 'p') + ? 2 : 4); if (argc - optind < expected_operands) {