diff options
author | Jim Meyering <jim@meyering.net> | 2004-06-21 15:35:12 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-06-21 15:35:12 +0000 |
commit | f53347b996942a516b5039b18d8df1a1ff4ed37e (patch) | |
tree | 23d274d815a0a7418214284c2e3aa72d497d646c /src | |
parent | 777a96db68395c6e09c1acb7cfe0edebe315ed86 (diff) | |
download | coreutils-f53347b996942a516b5039b18d8df1a1ff4ed37e.tar.xz |
(main): Don't segfault when calculating the
expected number of operands for `mknod NAME'.
Diffstat (limited to 'src')
-rw-r--r-- | src/mknod.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mknod.c b/src/mknod.c index 58f12f9b2..a3a9d2270 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) { |