From 75ca8d074bacb6896d770993b93161c40aa31b9f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Oct 2024 04:23:29 +0200 Subject: [PATCH] hexdump: accept hex numbers in -n, closes 16195 function old new delta hexdump_main 366 383 +17 Signed-off-by: Denys Vlasenko --- util-linux/hexdump.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index c46ffeca7..5a938e783 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c @@ -127,15 +127,20 @@ int hexdump_main(int argc, char **argv) if (ch == 'f') { bb_dump_addfile(dumper, optarg); } /* else */ - if (ch == 'n') { - dumper->dump_length = xatoi_positive(optarg); + if (ch == 'n') { /* compat: -n accepts hex numbers too */ + dumper->dump_length = xstrtou_range_sfx( + optarg, + /*base:*/ 0, + /*lo:*/ 0, /*hi:*/ INT_MAX, + kmg_i_suffixes + ); } /* else */ if (ch == 's') { /* compat: -s accepts hex numbers too */ dumper->dump_skip = xstrtoull_range_sfx( optarg, /*base:*/ 0, /*lo:*/ 0, /*hi:*/ OFF_T_MAX, - bkm_suffixes + kmg_i_suffixes ); } /* else */ if (ch == 'v') {