diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-18 02:47:35 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-18 02:47:35 +0100 |
| commit | a0bef7cc276476e69e2496e728bf97b32d3b561d (patch) | |
| tree | dfd921a5ea67c5c72d246d35342914272e1703c7 /libbb | |
| parent | 860491c5251886c40d6dfb89723f392db3a397a9 (diff) | |
| download | busybox-w32-a0bef7cc276476e69e2496e728bf97b32d3b561d.tar.gz busybox-w32-a0bef7cc276476e69e2496e728bf97b32d3b561d.tar.bz2 busybox-w32-a0bef7cc276476e69e2496e728bf97b32d3b561d.zip | |
hexdump: fix hexdump -n1 -ve '8/2 ""' SEGV. Closes 4478
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/dump.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 919fe135c..7e435643b 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
| @@ -71,7 +71,8 @@ static NOINLINE int bb_dump_size(FS *fs) | |||
| 71 | * skip any special chars -- save precision in | 71 | * skip any special chars -- save precision in |
| 72 | * case it's a %s format. | 72 | * case it's a %s format. |
| 73 | */ | 73 | */ |
| 74 | while (strchr(index_str + 1, *++fmt)); | 74 | while (strchr(index_str + 1, *++fmt)) |
| 75 | continue; | ||
| 75 | if (*fmt == '.' && isdigit(*++fmt)) { | 76 | if (*fmt == '.' && isdigit(*++fmt)) { |
| 76 | prec = atoi(fmt); | 77 | prec = atoi(fmt); |
| 77 | while (isdigit(*++fmt)) | 78 | while (isdigit(*++fmt)) |
| @@ -99,8 +100,8 @@ static NOINLINE int bb_dump_size(FS *fs) | |||
| 99 | static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) | 100 | static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) |
| 100 | { | 101 | { |
| 101 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; | 102 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; |
| 102 | PR *pr; | ||
| 103 | FU *fu; | 103 | FU *fu; |
| 104 | PR *pr; | ||
| 104 | char *p1, *p2, *p3; | 105 | char *p1, *p2, *p3; |
| 105 | char savech, *fmtp; | 106 | char savech, *fmtp; |
| 106 | const char *byte_count_str; | 107 | const char *byte_count_str; |
| @@ -292,16 +293,18 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) | |||
| 292 | * interprets any data at all, and has no iteration count, | 293 | * interprets any data at all, and has no iteration count, |
| 293 | * repeat it as necessary. | 294 | * repeat it as necessary. |
| 294 | * | 295 | * |
| 295 | * if, rep count is greater than 1, no trailing whitespace | 296 | * if rep count is greater than 1, no trailing whitespace |
| 296 | * gets output from the last iteration of the format unit. | 297 | * gets output from the last iteration of the format unit. |
| 297 | */ | 298 | */ |
| 298 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { | 299 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
| 299 | if (!fu->nextfu && fs->bcnt < dumper->blocksize | 300 | if (!fu->nextfu |
| 300 | && !(fu->flags & F_SETREP) && fu->bcnt | 301 | && fs->bcnt < dumper->blocksize |
| 302 | && !(fu->flags & F_SETREP) | ||
| 303 | && fu->bcnt | ||
| 301 | ) { | 304 | ) { |
| 302 | fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt; | 305 | fu->reps += (dumper->blocksize - fs->bcnt) / fu->bcnt; |
| 303 | } | 306 | } |
| 304 | if (fu->reps > 1) { | 307 | if (fu->reps > 1 && fu->nextpr) { |
| 305 | for (pr = fu->nextpr;; pr = pr->nextpr) | 308 | for (pr = fu->nextpr;; pr = pr->nextpr) |
| 306 | if (!pr->nextpr) | 309 | if (!pr->nextpr) |
| 307 | break; | 310 | break; |
| @@ -721,7 +724,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) | |||
| 721 | p = fmt; | 724 | p = fmt; |
| 722 | for (;;) { | 725 | for (;;) { |
| 723 | p = skip_whitespace(p); | 726 | p = skip_whitespace(p); |
| 724 | if (!*p) { | 727 | if (*p == '\0') { |
| 725 | break; | 728 | break; |
| 726 | } | 729 | } |
| 727 | 730 | ||
| @@ -749,7 +752,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) | |||
| 749 | 752 | ||
| 750 | /* skip slash and trailing white space */ | 753 | /* skip slash and trailing white space */ |
| 751 | if (*p == '/') { | 754 | if (*p == '/') { |
| 752 | p = skip_whitespace(++p); | 755 | p = skip_whitespace(p + 1); |
| 753 | } | 756 | } |
| 754 | 757 | ||
| 755 | /* byte count */ | 758 | /* byte count */ |
| @@ -763,7 +766,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) | |||
| 763 | } | 766 | } |
| 764 | tfu->bcnt = atoi(savep); | 767 | tfu->bcnt = atoi(savep); |
| 765 | /* skip trailing white space */ | 768 | /* skip trailing white space */ |
| 766 | p = skip_whitespace(++p); | 769 | p = skip_whitespace(p + 1); |
| 767 | } | 770 | } |
| 768 | 771 | ||
| 769 | /* format */ | 772 | /* format */ |
| @@ -771,7 +774,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) | |||
| 771 | bb_error_msg_and_die("bad format {%s}", fmt); | 774 | bb_error_msg_and_die("bad format {%s}", fmt); |
| 772 | } | 775 | } |
| 773 | for (savep = ++p; *p != '"';) { | 776 | for (savep = ++p; *p != '"';) { |
| 774 | if (*p++ == 0) { | 777 | if (*p++ == '\0') { |
| 775 | bb_error_msg_and_die("bad format {%s}", fmt); | 778 | bb_error_msg_and_die("bad format {%s}", fmt); |
| 776 | } | 779 | } |
| 777 | } | 780 | } |
| @@ -782,7 +785,7 @@ void FAST_FUNC bb_dump_add(dumper_t* pub_dumper, const char *fmt) | |||
| 782 | 785 | ||
| 783 | /* alphabetic escape sequences have to be done in place */ | 786 | /* alphabetic escape sequences have to be done in place */ |
| 784 | for (p2 = p1;; ++p1, ++p2) { | 787 | for (p2 = p1;; ++p1, ++p2) { |
| 785 | if (!*p1) { | 788 | if (*p1 == '\0') { |
| 786 | *p2 = *p1; | 789 | *p2 = *p1; |
| 787 | break; | 790 | break; |
| 788 | } | 791 | } |
