aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-04-30 05:11:57 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-04-30 05:11:57 +0000
commit8f07a1510757654df50f7c7a8f4b8619841ee2a7 (patch)
tree8a7e45499a4370a6abc60899dd3aae5c48a306d0
parentc9ccc500033571e88f4c98f27d55dc80992cb130 (diff)
downloadbusybox-w32-8f07a1510757654df50f7c7a8f4b8619841ee2a7.tar.gz
busybox-w32-8f07a1510757654df50f7c7a8f4b8619841ee2a7.tar.bz2
busybox-w32-8f07a1510757654df50f7c7a8f4b8619841ee2a7.zip
On Wednesday 13 April 2005 09:12 pm, Shaun Jackman wrote:
> This patch fixes a memory leak in hash_file by using the BUFFER macros > instead of xmalloc. Please apply. git-svn-id: svn://busybox.net/trunk/busybox@10207 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/md5_sha1_sum.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 189a90778..914f81fa2 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -49,34 +49,21 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
49 49
50static uint8_t *hash_file(const char *filename, uint8_t hash_algo) 50static uint8_t *hash_file(const char *filename, uint8_t hash_algo)
51{ 51{
52 uint8_t *hash_value_bin; 52 int src_fd = strcmp(filename, "-") == 0 ? STDIN_FILENO :
53 uint8_t *hash_value = NULL; 53 open(filename, O_RDONLY);
54 uint8_t hash_length; 54 if (src_fd == -1) {
55 int src_fd;
56
57 if (strcmp(filename, "-") == 0) {
58 src_fd = STDIN_FILENO;
59 } else {
60 src_fd = open(filename, O_RDONLY);
61 }
62
63 if (hash_algo == HASH_MD5) {
64 hash_length = 16;
65 } else {
66 hash_length = 20;
67 }
68
69 hash_value_bin = xmalloc(hash_length);
70
71 if ((src_fd != -1) && (hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2)) {
72 hash_value = hash_bin_to_hex(hash_value_bin, hash_length);
73 } else {
74 bb_perror_msg("%s", filename); 55 bb_perror_msg("%s", filename);
56 return NULL;
57 } else {
58 uint8_t *hash_value;
59 RESERVE_CONFIG_UBUFFER(hash_value_bin, 20);
60 hash_value = hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2 ?
61 hash_bin_to_hex(hash_value_bin, hash_algo == HASH_MD5 ? 16 : 20) :
62 NULL;
63 RELEASE_CONFIG_BUFFER(hash_value_bin);
64 close(src_fd);
65 return hash_value;
75 } 66 }
76
77 close(src_fd);
78
79 return(hash_value);
80} 67}
81 68
82/* This could become a common function for md5 as well, by using md5_stream */ 69/* This could become a common function for md5 as well, by using md5_stream */