diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2007-01-28 16:37:10 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2007-01-28 16:37:10 +0000 |
commit | 55b8488cba75efc02fbf27894891e6597496e36b (patch) | |
tree | 9926ec26ec29e016ffccd4a715c17baac06178c5 /usr.bin/hexdump | |
parent | fe0ec35eadd3b867b0144c619fb6b0b9cccb7cd1 (diff) |
Accept a leading 0x for the -n length parameter.
Correctly check for out-of-bounds values for -s skip parameter, and use
strtoll to parse it instead of strtol since this is an off_t value.
Diffstat (limited to 'usr.bin/hexdump')
-rw-r--r-- | usr.bin/hexdump/hexdump.1 | 15 | ||||
-rw-r--r-- | usr.bin/hexdump/hexdump.c | 6 | ||||
-rw-r--r-- | usr.bin/hexdump/hexdump.h | 4 | ||||
-rw-r--r-- | usr.bin/hexdump/hexsyntax.c | 13 |
4 files changed, 28 insertions, 10 deletions
diff --git a/usr.bin/hexdump/hexdump.1 b/usr.bin/hexdump/hexdump.1 index 753e330dee4..434233b85a9 100644 --- a/usr.bin/hexdump/hexdump.1 +++ b/usr.bin/hexdump/hexdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: hexdump.1,v 1.14 2003/06/03 02:56:09 millert Exp $ +.\" $OpenBSD: hexdump.1,v 1.15 2007/01/28 16:37:09 miod Exp $ .\" $NetBSD: hexdump.1,v 1.14 2001/12/07 14:46:24 bjh21 Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -92,6 +92,19 @@ are ignored. Interpret only .Ar length bytes of input. +By default, +.Ar length +is interpreted as a decimal number. +With a leading +.Cm 0x +or +.Cm 0X , +.Ar length +is interpreted as a hexadecimal number, +otherwise, with a leading +.Cm 0 , +.Ar length +is interpreted as an octal number. .It Fl o .Em Two-byte octal display . Display the input offset in hexadecimal, followed by eight diff --git a/usr.bin/hexdump/hexdump.c b/usr.bin/hexdump/hexdump.c index 8fc79f38358..18cc3f7e507 100644 --- a/usr.bin/hexdump/hexdump.c +++ b/usr.bin/hexdump/hexdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hexdump.c,v 1.11 2003/07/10 00:06:51 david Exp $ */ +/* $OpenBSD: hexdump.c,v 1.12 2007/01/28 16:37:09 miod Exp $ */ /* $NetBSD: hexdump.c,v 1.7 1997/10/19 02:34:06 lukem Exp $ */ /* @@ -38,7 +38,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)hexdump.c 5.5 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$OpenBSD: hexdump.c,v 1.11 2003/07/10 00:06:51 david Exp $"; +static char rcsid[] = "$OpenBSD: hexdump.c,v 1.12 2007/01/28 16:37:09 miod Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -50,7 +50,7 @@ static char rcsid[] = "$OpenBSD: hexdump.c,v 1.11 2003/07/10 00:06:51 david Exp FS *fshead; /* head of format strings */ int blocksize; /* data block size */ int exitval; /* final exit value */ -int length = -1; /* max bytes to read */ +long length = -1; /* max bytes to read */ int main(int, char **); diff --git a/usr.bin/hexdump/hexdump.h b/usr.bin/hexdump/hexdump.h index 17c41061ba5..440b94e8132 100644 --- a/usr.bin/hexdump/hexdump.h +++ b/usr.bin/hexdump/hexdump.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hexdump.h,v 1.7 2003/06/03 02:56:09 millert Exp $ */ +/* $OpenBSD: hexdump.h,v 1.8 2007/01/28 16:37:09 miod Exp $ */ /* $NetBSD: hexdump.h,v 1.7 2001/12/07 15:14:29 bjh21 Exp $ */ /* @@ -76,7 +76,7 @@ extern int deprecated; /* od compatibility */ extern FU *endfu; /* format at end-of-data */ extern int exitval; /* final exit value */ extern FS *fshead; /* head of format strings list */ -extern int length; /* max bytes to read */ +extern long length; /* max bytes to read */ extern off_t skip; /* bytes to skip */ extern enum _vflag vflag; diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c index 22d607a770d..46aaf7032aa 100644 --- a/usr.bin/hexdump/hexsyntax.c +++ b/usr.bin/hexdump/hexsyntax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hexsyntax.c,v 1.8 2003/06/12 20:58:09 deraadt Exp $ */ +/* $OpenBSD: hexsyntax.c,v 1.9 2007/01/28 16:37:09 miod Exp $ */ /* $NetBSD: hexsyntax.c,v 1.8 1998/04/08 23:48:57 jeremy Exp $ */ /*- @@ -32,12 +32,13 @@ #ifndef lint /*static char sccsid[] = "from: @(#)hexsyntax.c 5.2 (Berkeley) 5/8/90";*/ -static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.8 2003/06/12 20:58:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hexsyntax.c,v 1.9 2007/01/28 16:37:09 miod Exp $"; #endif /* not lint */ #include <sys/types.h> #include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -80,7 +81,9 @@ newsyntax(int argc, char ***argvp) addfile(optarg); break; case 'n': - if ((length = atoi(optarg)) < 0) + errno = 0; + if ((length = strtol(optarg, NULL, 0)) < 0 || + errno != 0) errx(1, "%s: bad length value", optarg); break; case 'o': @@ -88,7 +91,9 @@ newsyntax(int argc, char ***argvp) add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\""); break; case 's': - if ((skip = strtol(optarg, &p, 0)) < 0) + errno = 0; + if ((skip = (off_t)strtoll(optarg, &p, 0)) < 0 || + errno != 0) errx(1, "%s: bad skip value", optarg); switch(*p) { case 'b': |