diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-08-02 11:16:48 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-08-02 11:16:48 +0000 |
commit | 98e1a6f4bec9e9070c764ce030fd0dbc2507b395 (patch) | |
tree | 2067a93696822e56b8e86716cdbe0b4f32e80fa0 | |
parent | 9820aa6ec402f684eaf562aa3853b28d0a9dd387 (diff) |
use strtoul and check errors; from freebsd
-rw-r--r-- | sbin/mknod/mknod.8 | 10 | ||||
-rw-r--r-- | sbin/mknod/mknod.c | 24 |
2 files changed, 30 insertions, 4 deletions
diff --git a/sbin/mknod/mknod.8 b/sbin/mknod/mknod.8 index 1e78961fdc2..3c9cd8bd88e 100644 --- a/sbin/mknod/mknod.8 +++ b/sbin/mknod/mknod.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mknod.8,v 1.2 1996/06/23 14:31:03 deraadt Exp $ +.\" $OpenBSD: mknod.8,v 1.3 1996/08/02 11:16:47 deraadt Exp $ .\" $NetBSD: mknod.8,v 1.9 1995/08/10 23:47:32 jtc Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 @@ -92,6 +92,14 @@ The minor device number tells the kernel which subunit the node corresponds to on the device; for example, a subunit may be a filesystem partition or a tty line. +.Pp +Major and minor device numbers can be given in any format acceptable to +.Xr strtoul 3 , +so that a leading +.Ql 0x +indicates a hexadecimal number, and a leading +.Ql 0 +will cause the number to be interpreted as octal. .El .Sh SEE ALSO .Xr mknod 2 , diff --git a/sbin/mknod/mknod.c b/sbin/mknod/mknod.c index dc70189e751..b6927e41162 100644 --- a/sbin/mknod/mknod.c +++ b/sbin/mknod/mknod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mknod.c,v 1.2 1996/06/23 14:31:03 deraadt Exp $ */ +/* $OpenBSD: mknod.c,v 1.3 1996/08/02 11:16:47 deraadt Exp $ */ /* $NetBSD: mknod.c,v 1.8 1995/08/11 00:08:18 jtc Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: mknod.c,v 1.2 1996/06/23 14:31:03 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mknod.c,v 1.3 1996/08/02 11:16:47 deraadt Exp $"; #endif #endif /* not lint */ @@ -65,6 +65,9 @@ main(argc, argv) int argc; char **argv; { + dev_t dev; + char *endp; + u_int major, minor; mode_t mode; if (argc != 5) { @@ -82,7 +85,22 @@ main(argc, argv) /* NOTREACHED */ } - if (mknod(argv[1], mode, makedev(atoi(argv[3]), atoi(argv[4]))) < 0) { + major = (long)strtoul(argv[3], &endp, 0); + if (endp == argv[3] || *endp != '\0') { + errx(1, "non-numeric major number."); + /* NOTREACHED */ + } + minor = (long)strtoul(argv[4], &endp, 0); + if (endp == argv[3] || *endp != '\0') { + errx(1, "non-numeric minor number."); + /* NOTREACHED */ + } + dev = makedev(major, minor); + if (major(dev) != major || minor(dev) != minor) { + errx(1, "major or minor number too large"); + /* NOTREACHED */ + } + if (mknod(argv[1], mode, dev) < 0) { err(1, "%s", argv[1]); /* NOTREACHED */ } |