summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2017-04-09 15:03:54 +0000
committerjsing <>2017-04-09 15:03:54 +0000
commitafaf561c5fbef9787c7015f86ec44e61a764009b (patch)
tree9194938e3291ef051a8b4ce031e9baba1edb0185
parent978d8c2620ea265519c6ba475c5ea70385b3f7e7 (diff)
downloadopenbsd-afaf561c5fbef9787c7015f86ec44e61a764009b.tar.gz
openbsd-afaf561c5fbef9787c7015f86ec44e61a764009b.tar.bz2
openbsd-afaf561c5fbef9787c7015f86ec44e61a764009b.zip
With recallocarray() BUF_MEM_grow() is essentially the same as
BUF_MEM_grow_clean() (the only difference is clearing on internal down sizing), so make it a wrapper. ok beck@ deraadt@
-rw-r--r--src/lib/libcrypto/buffer/buffer.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
index 2e4959a58d..f15b93d26c 100644
--- a/src/lib/libcrypto/buffer/buffer.c
+++ b/src/lib/libcrypto/buffer/buffer.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: buffer.c,v 1.24 2017/03/16 13:29:56 jsing Exp $ */ 1/* $OpenBSD: buffer.c,v 1.25 2017/04/09 15:03:54 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -97,33 +97,7 @@ BUF_MEM_free(BUF_MEM *a)
97int 97int
98BUF_MEM_grow(BUF_MEM *str, size_t len) 98BUF_MEM_grow(BUF_MEM *str, size_t len)
99{ 99{
100 char *ret; 100 return BUF_MEM_grow_clean(str, len);
101 size_t n;
102
103 if (str->length >= len) {
104 str->length = len;
105 return (len);
106 }
107 if (str->max >= len) {
108 str->length = len;
109 return (len);
110 }
111 /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
112 if (len > LIMIT_BEFORE_EXPANSION) {
113 BUFerror(ERR_R_MALLOC_FAILURE);
114 return 0;
115 }
116 n = (len + 3) / 3 * 4;
117 ret = recallocarray(str->data, str->max, n, 1);
118 if (ret == NULL) {
119 BUFerror(ERR_R_MALLOC_FAILURE);
120 len = 0;
121 } else {
122 str->data = ret;
123 str->max = n;
124 str->length = len;
125 }
126 return (len);
127} 101}
128 102
129int 103int