diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-06 16:23:50 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-06 16:23:50 +0100 |
| commit | 59655077c5bf176f01d8d277665ebb92263704ed (patch) | |
| tree | 0d4393ea09ebe90e35866d27041faf6372f6e87e /miscutils | |
| parent | 17eedcad9406c43beddab3906c8c693626c351fb (diff) | |
| download | busybox-w32-59655077c5bf176f01d8d277665ebb92263704ed.tar.gz busybox-w32-59655077c5bf176f01d8d277665ebb92263704ed.tar.bz2 busybox-w32-59655077c5bf176f01d8d277665ebb92263704ed.zip | |
preparatory cleanups for seamless uncompression improvements
unpack_gz_stream_with_info: fix buggy error check
man: fix possible accesses past the end of a string
move seamless uncompression helpers from read_printf.c to open_transformer.c
function old new delta
show_manpage 153 212 +59
unpack_gz_stream_with_info 520 539 +19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/man.c | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/miscutils/man.c b/miscutils/man.c index 3bf7e84b6..611466349 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
| @@ -30,16 +30,6 @@ echo ".pl \n(nlu+10" | |||
| 30 | 30 | ||
| 31 | */ | 31 | */ |
| 32 | 32 | ||
| 33 | #if ENABLE_FEATURE_SEAMLESS_LZMA | ||
| 34 | #define Z_SUFFIX ".lzma" | ||
| 35 | #elif ENABLE_FEATURE_SEAMLESS_BZ2 | ||
| 36 | #define Z_SUFFIX ".bz2" | ||
| 37 | #elif ENABLE_FEATURE_SEAMLESS_GZ | ||
| 38 | #define Z_SUFFIX ".gz" | ||
| 39 | #else | ||
| 40 | #define Z_SUFFIX "" | ||
| 41 | #endif | ||
| 42 | |||
| 43 | static int show_manpage(const char *pager, char *man_filename, int man, int level); | 33 | static int show_manpage(const char *pager, char *man_filename, int man, int level); |
| 44 | 34 | ||
| 45 | static int run_pipe(const char *pager, char *man_filename, int man, int level) | 35 | static int run_pipe(const char *pager, char *man_filename, int man, int level) |
| @@ -102,7 +92,7 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level) | |||
| 102 | 92 | ||
| 103 | /* Links do not have .gz extensions, even if manpage | 93 | /* Links do not have .gz extensions, even if manpage |
| 104 | * is compressed */ | 94 | * is compressed */ |
| 105 | man_filename = xasprintf("%s/%s" Z_SUFFIX, man_filename, linkname); | 95 | man_filename = xasprintf("%s/%s", man_filename, linkname); |
| 106 | free(line); | 96 | free(line); |
| 107 | /* Note: we leak "new" man_filename string as well... */ | 97 | /* Note: we leak "new" man_filename string as well... */ |
| 108 | if (show_manpage(pager, man_filename, man, level + 1)) | 98 | if (show_manpage(pager, man_filename, man, level + 1)) |
| @@ -124,32 +114,37 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level) | |||
| 124 | return 1; | 114 | return 1; |
| 125 | } | 115 | } |
| 126 | 116 | ||
| 127 | /* man_filename is of the form "/dir/dir/dir/name.s" Z_SUFFIX */ | 117 | /* man_filename is of the form "/dir/dir/dir/name.s" */ |
| 128 | static int show_manpage(const char *pager, char *man_filename, int man, int level) | 118 | static int show_manpage(const char *pager, char *man_filename, int man, int level) |
| 129 | { | 119 | { |
| 120 | #if SEAMLESS_COMPRESSION | ||
| 121 | /* We leak this allocation... */ | ||
| 122 | char *filename_with_zext = xasprintf("%s.lzma", man_filename); | ||
| 123 | char *ext = strrchr(filename_with_zext, '.') + 1; | ||
| 124 | #endif | ||
| 125 | |||
| 130 | #if ENABLE_FEATURE_SEAMLESS_LZMA | 126 | #if ENABLE_FEATURE_SEAMLESS_LZMA |
| 127 | if (run_pipe(pager, filename_with_zext, man, level)) | ||
| 128 | return 1; | ||
| 129 | #endif | ||
| 130 | #if ENABLE_FEATURE_SEAMLESS_XZ | ||
| 131 | strcpy(ext, "xz"); | ||
| 131 | if (run_pipe(pager, man_filename, man, level)) | 132 | if (run_pipe(pager, man_filename, man, level)) |
| 132 | return 1; | 133 | return 1; |
| 133 | #endif | 134 | #endif |
| 134 | |||
| 135 | #if ENABLE_FEATURE_SEAMLESS_BZ2 | 135 | #if ENABLE_FEATURE_SEAMLESS_BZ2 |
| 136 | #if ENABLE_FEATURE_SEAMLESS_LZMA | 136 | strcpy(ext, "bz2"); |
| 137 | strcpy(strrchr(man_filename, '.') + 1, "bz2"); | ||
| 138 | #endif | ||
| 139 | if (run_pipe(pager, man_filename, man, level)) | 137 | if (run_pipe(pager, man_filename, man, level)) |
| 140 | return 1; | 138 | return 1; |
| 141 | #endif | 139 | #endif |
| 142 | |||
| 143 | #if ENABLE_FEATURE_SEAMLESS_GZ | 140 | #if ENABLE_FEATURE_SEAMLESS_GZ |
| 144 | #if ENABLE_FEATURE_SEAMLESS_LZMA || ENABLE_FEATURE_SEAMLESS_BZ2 | 141 | strcpy(ext, "gz"); |
| 145 | strcpy(strrchr(man_filename, '.') + 1, "gz"); | ||
| 146 | #endif | ||
| 147 | if (run_pipe(pager, man_filename, man, level)) | 142 | if (run_pipe(pager, man_filename, man, level)) |
| 148 | return 1; | 143 | return 1; |
| 149 | #endif | 144 | #endif |
| 150 | 145 | ||
| 151 | #if ENABLE_FEATURE_SEAMLESS_LZMA || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_GZ | 146 | #if SEAMLESS_COMPRESSION |
| 152 | *strrchr(man_filename, '.') = '\0'; | 147 | ext[-1] = '\0'; |
| 153 | #endif | 148 | #endif |
| 154 | if (run_pipe(pager, man_filename, man, level)) | 149 | if (run_pipe(pager, man_filename, man, level)) |
| 155 | return 1; | 150 | return 1; |
| @@ -262,7 +257,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
| 262 | /* Search for cat, then man page */ | 257 | /* Search for cat, then man page */ |
| 263 | while (cat0man1 < 2) { | 258 | while (cat0man1 < 2) { |
| 264 | int found_here; | 259 | int found_here; |
| 265 | man_filename = xasprintf("%s/%s%.*s/%s.%.*s" Z_SUFFIX, | 260 | man_filename = xasprintf("%s/%s%.*s/%s.%.*s", |
| 266 | cur_path, | 261 | cur_path, |
| 267 | "cat\0man" + (cat0man1 * 4), | 262 | "cat\0man" + (cat0man1 * 4), |
| 268 | sect_len, cur_sect, | 263 | sect_len, cur_sect, |
