Discussion:
hexdump(1) - bug when skip == sb.st_size
Michal Mazurek
2016-02-08 13:11:19 UTC
Permalink
When running
hexdump -s $NUM file
where NUM is the size of the file, hexdump will print the entire file,
instead of skipping over the content.

"od -j $NUM" has the same issue.

Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/hexdump/display.c,v
retrieving revision 1.21
diff -u -p -r1.21 display.c
--- display.c 16 Jan 2015 06:40:08 -0000 1.21
+++ display.c 8 Feb 2016 12:39:12 -0000
@@ -329,7 +326,7 @@ doskip(const char *fname, int statok)
if (fstat(fileno(stdin), &sb))
err(1, "fstat %s", fname);
if (S_ISREG(sb.st_mode)) {
- if (skip >= sb.st_size) {
+ if (skip > sb.st_size) {
address += sb.st_size;
skip -= sb.st_size;
} else {

This bug was discovered by tdm.
--
Michal Mazurek
Ingo Schwarze
2016-02-08 16:38:59 UTC
Permalink
Hi,
Post by Michal Mazurek
When running
hexdump -s $NUM file
where NUM is the size of the file, hexdump will print the entire file,
instead of skipping over the content.
This looks correct and works for me.

OK to commit?
Ingo
Post by Michal Mazurek
"od -j $NUM" has the same issue.
Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/hexdump/display.c,v
retrieving revision 1.21
diff -u -p -r1.21 display.c
--- display.c 16 Jan 2015 06:40:08 -0000 1.21
+++ display.c 8 Feb 2016 12:39:12 -0000
@@ -329,7 +326,7 @@ doskip(const char *fname, int statok)
if (fstat(fileno(stdin), &sb))
err(1, "fstat %s", fname);
if (S_ISREG(sb.st_mode)) {
- if (skip >= sb.st_size) {
+ if (skip > sb.st_size) {
address += sb.st_size;
skip -= sb.st_size;
} else {
This bug was discovered by tdm.
Loading...