[PATCH] hexdump: don't unconditionally limit the usable address range

dietmar.schindler at manroland-web.com dietmar.schindler at manroland-web.com
Fri Mar 22 13:00:06 UTC 2013


For example the command

        hexdump -s 0xc0216000 /dev/kmem | head -1

outputs

        hexdump: number 0xc0216000 is not in 0..2147483647 range

without the patch, and

        c0216000 7d61 5b78 4e80 0020 7c08 02a6 9001 0004

with it (compiled with CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64").

diff --git a/util-linux/hexdump.c b/usr/local/home/armali/BusyBox/source/util-linux/hexdump.c
index 9a312f9..8cf94fd 100644
--- a/util-linux/hexdump.c
+++ b/usr/local/home/armali/BusyBox/source/util-linux/hexdump.c
@@ -116,7 +116,15 @@ int hexdump_main(int argc, char **argv)
                        dumper->dump_length = xatoi_positive(optarg);
                } /* else */
                if (ch == 's') { /* compat: -s accepts hex numbers too */
-                       dumper->dump_skip = xstrtoul_range_sfx(optarg, /*base:*/ 0, /*lo:*/ 0, /*hi:*/ LONG_MAX, suffixes);
+                       dumper->dump_skip = xstrtoll_range_sfx(optarg, /*base:*/ 0,
+                                                                                                                        /*lo:*/ 0,
+#if _LARGEFILE_SOURCE && _FILE_OFFSET_BITS > 32
+/* only if we have fseeko and long long off_t */
+                                                                                                                        /*hi:*/ LLONG_MAX,
+#else
+                                                                                                                        /*hi:*/ LONG_MAX,
+#endif
+                                                                                                                                        suffixes);
                } /* else */
                if (ch == 'v') {
                        dumper->dump_vflag = ALL;

diff --git a/libbb/dump.c b/usr/local/home/armali/BusyBox/source/libbb/dump.c
index 7e43564..b3c3230 100644
--- a/libbb/dump.c
+++ b/usr/local/home/armali/BusyBox/source/libbb/dump.c
@@ -333,6 +333,9 @@ static void do_skip(priv_dumper_t *dumper, const char *fname, int statok)
                        return;
                }
        }
+#if _LARGEFILE_SOURCE  /* only if we have fseeko */
+       #define fseek   fseeko
+#endif
        if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) {
                bb_simple_perror_msg_and_die(fname);
        }

--
Best regards,
Dietmar Schindler
________________________________________
manroland web systems GmbH -- Managing Director: Eckhard Hoerner-Marass
Registered Office: Augsburg -- Trade Register: AG Augsburg -- HRB-No. 26816 -- VAT: DE281389840

Confidentiality note:
This eMail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are hereby notified that any use or dissemination of this communication is strictly prohibited. If you have received this eMail in error, then please delete this eMail.

! Please consider your environmental responsibility before printing this eMail
________________________________________



More information about the busybox mailing list