diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-04-16 18:56:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-04-16 18:56:36 +0200 |
commit | 43a3d50e14902e746ee53b7cfb63fe190bd5387f (patch) | |
tree | a1656b41461ea7a7a0544fd67a34d8c3fb668322 /coreutils/md5_sha1_sum.c | |
parent | 88a838438819f7a5224a2ab3ea99219f9a666bf4 (diff) | |
download | busybox-w32-43a3d50e14902e746ee53b7cfb63fe190bd5387f.tar.gz busybox-w32-43a3d50e14902e746ee53b7cfb63fe190bd5387f.tar.bz2 busybox-w32-43a3d50e14902e746ee53b7cfb63fe190bd5387f.zip |
md5/sha1sum: better fix for small resource leak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/md5_sha1_sum.c')
-rw-r--r-- | coreutils/md5_sha1_sum.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 8270d97e2..050d46701 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -100,22 +100,18 @@ static uint8_t *hash_file(const char *filename) | |||
100 | md5_ctx_t md5; | 100 | md5_ctx_t md5; |
101 | } context; | 101 | } context; |
102 | uint8_t *hash_value = NULL; | 102 | uint8_t *hash_value = NULL; |
103 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); | ||
104 | void FAST_FUNC (*update)(void*, const void*, size_t); | 103 | void FAST_FUNC (*update)(void*, const void*, size_t); |
105 | void FAST_FUNC (*final)(void*, void*); | 104 | void FAST_FUNC (*final)(void*, void*); |
106 | char hash_algo; | 105 | char hash_algo; |
107 | 106 | ||
108 | src_fd = open_or_warn_stdin(filename); | 107 | src_fd = open_or_warn_stdin(filename); |
109 | if (src_fd < 0) { | 108 | if (src_fd < 0) { |
110 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
111 | RELEASE_CONFIG_BUFFER(in_buf); | ||
112 | } | ||
113 | return NULL; | 109 | return NULL; |
114 | } | 110 | } |
115 | 111 | ||
116 | hash_algo = applet_name[3]; | 112 | hash_algo = applet_name[3]; |
117 | 113 | ||
118 | /* figure specific hash algorithims */ | 114 | /* figure specific hash algorithms */ |
119 | if (ENABLE_MD5SUM && hash_algo == HASH_MD5) { | 115 | if (ENABLE_MD5SUM && hash_algo == HASH_MD5) { |
120 | md5_begin(&context.md5); | 116 | md5_begin(&context.md5); |
121 | update = (void*)md5_hash; | 117 | update = (void*)md5_hash; |
@@ -140,17 +136,18 @@ static uint8_t *hash_file(const char *filename) | |||
140 | xfunc_die(); /* can't reach this */ | 136 | xfunc_die(); /* can't reach this */ |
141 | } | 137 | } |
142 | 138 | ||
143 | while ((count = safe_read(src_fd, in_buf, 4096)) > 0) { | 139 | { |
144 | update(&context, in_buf, count); | 140 | RESERVE_CONFIG_UBUFFER(in_buf, 4096); |
145 | } | 141 | while ((count = safe_read(src_fd, in_buf, 4096)) > 0) { |
146 | 142 | update(&context, in_buf, count); | |
147 | if (count == 0) { | 143 | } |
148 | final(&context, in_buf); | 144 | if (count == 0) { |
149 | hash_value = hash_bin_to_hex(in_buf, hash_len); | 145 | final(&context, in_buf); |
146 | hash_value = hash_bin_to_hex(in_buf, hash_len); | ||
147 | } | ||
148 | RELEASE_CONFIG_BUFFER(in_buf); | ||
150 | } | 149 | } |
151 | 150 | ||
152 | RELEASE_CONFIG_BUFFER(in_buf); | ||
153 | |||
154 | if (src_fd != STDIN_FILENO) { | 151 | if (src_fd != STDIN_FILENO) { |
155 | close(src_fd); | 152 | close(src_fd); |
156 | } | 153 | } |