diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-01 19:05:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-12-01 19:05:40 +0000 |
commit | 060e2f92d8cf15ad99f36a763859d86a78c591e2 (patch) | |
tree | ebcc8548a33e8e8265b5bac3007a5fb46b98050f /sbin/ncheck_ffs | |
parent | f27dfbb769d62aa95bb2e6714a6fe51aa9e268f5 (diff) |
use strtoul() instead of atoi()
Diffstat (limited to 'sbin/ncheck_ffs')
-rw-r--r-- | sbin/ncheck_ffs/ncheck_ffs.8 | 8 | ||||
-rw-r--r-- | sbin/ncheck_ffs/ncheck_ffs.c | 75 |
2 files changed, 52 insertions, 31 deletions
diff --git a/sbin/ncheck_ffs/ncheck_ffs.8 b/sbin/ncheck_ffs/ncheck_ffs.8 index db745549c56..a456cdf5ba9 100644 --- a/sbin/ncheck_ffs/ncheck_ffs.8 +++ b/sbin/ncheck_ffs/ncheck_ffs.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ncheck_ffs.8,v 1.13 2001/08/02 18:37:34 mpech Exp $ +.\" $OpenBSD: ncheck_ffs.8,v 1.14 2001/12/01 19:05:39 deraadt Exp $ .\" .\" Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> .\" All rights reserved. @@ -36,7 +36,7 @@ .Nd generate names from inode-numbers .Sh SYNOPSIS .Nm ncheck_ffs -.Op Fl i Ar numbers +.Op Fl i Ar number Op Ar ... .Op Fl ams .Ar filesystem .Sh DESCRIPTION @@ -48,8 +48,8 @@ Names of directories are followed by a .Pp The options are as follows: .Bl -tag -width Ds -.It Fl i Ar numbers -Report only those files whose inode numbers follows. +.It Fl i Ar number Op Ar ... +Report only those files whose inode numbers are as listed. .It Fl a Print the file names .Dq \&. diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c index ff518221ba1..07fc32194ca 100644 --- a/sbin/ncheck_ffs/ncheck_ffs.c +++ b/sbin/ncheck_ffs/ncheck_ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ncheck_ffs.c,v 1.7 2001/11/05 07:39:16 mpech Exp $ */ +/* $OpenBSD: ncheck_ffs.c,v 1.8 2001/12/01 19:05:39 deraadt Exp $ */ /*- * Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> @@ -31,7 +31,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.7 2001/11/05 07:39:16 mpech Exp $"; +static char rcsid[] = "$OpenBSD: ncheck_ffs.c,v 1.8 2001/12/01 19:05:39 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -301,7 +301,8 @@ scanonedir(ino, path) filesize = dp->di_size; for (i = 0; filesize > 0 && i < NDADDR; i++) { if (dp->di_db[i]) - searchdir(ino, dp->di_db[i], dblksize(sblock, dp, i), filesize, path); + searchdir(ino, dp->di_db[i], dblksize(sblock, dp, i), + filesize, path); filesize -= sblock->fs_bsize; } for (i = 0; filesize > 0 && i < NIADDR; i++) { @@ -331,7 +332,8 @@ dirindir(ino, blkno, ind_level, filesize, path) for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { blkno = idblk[i]; if (blkno) - searchdir(ino, blkno, sblock->fs_bsize, *filesize, path); + searchdir(ino, blkno, sblock->fs_bsize, + *filesize, path); } return; } @@ -417,10 +419,10 @@ rawname(name) if ((p = strrchr(name, '/')) == NULL) return name; *p = '\0'; - strcpy(newname, name); + strlcpy(newname, name, sizeof newname - 2); *p++ = '/'; - strcat(newname, "/r"); - strcat(newname, p); + strlcat(newname, "/r", sizeof newname); + strlcat(newname, p, sizeof newname); return(newname); } @@ -438,30 +440,49 @@ main(argc, argv) { struct stat stblock; struct fstab *fsp; + u_long ulval; + char *ep; int c; - ino_t ino; while ((c = getopt(argc, argv, "ai:ms")) != -1) switch (c) { - case 'a': - aflag++; - break; - case 'i': - iflag++; - addinode(strtoul(optarg, NULL, 10)); - while (optind < argc && (ino = strtoul(argv[optind], NULL, 10)) != 0) { - addinode(ino); - optind++; - } - break; - case 'm': - mflag++; - break; - case 's': - sflag++; - break; - case '?': - exit(2); + case 'a': + aflag++; + break; + case 'i': + iflag++; + + errno = 0; + ulval = strtoul(optarg, &ep, 10); + if (optarg[0] == '\0' || *ep != '\0') + errx(1, "%s is not a number", + optarg); + if (errno == ERANGE && ulval == ULONG_MAX) + errx(1, "%s is out or range", + optarg); + addinode((ino_t)ulval); + + while (optind < argc) { + errno = 0; + ulval = strtoul(argv[optind], &ep, 10); + if (argv[optind][0] == '\0' || *ep != '\0') + break; + if (errno == ERANGE && ulval == ULONG_MAX) + errx(1, "%s is out or range", + argv[optind]); + addinode((ino_t)ulval); + optind++; + } + break; + case 'm': + mflag++; + break; + case 's': + sflag++; + break; + default: + usage(); + exit(2); } if (optind != argc - 1) usage(); |