diff options
Diffstat (limited to 'sshbuf.c')
-rw-r--r-- | sshbuf.c | 22 |
1 files changed, 2 insertions, 20 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshbuf.c,v 1.11 2017/06/01 06:58:25 djm Exp $ */ | 1 | /* $OpenBSD: sshbuf.c,v 1.12 2018/07/09 21:56:06 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2011 Damien Miller | 3 | * Copyright (c) 2011 Damien Miller |
4 | * | 4 | * |
@@ -36,7 +36,6 @@ sshbuf_check_sanity(const struct sshbuf *buf) | |||
36 | (!buf->readonly && buf->d != buf->cd) || | 36 | (!buf->readonly && buf->d != buf->cd) || |
37 | buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX || | 37 | buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX || |
38 | buf->cd == NULL || | 38 | buf->cd == NULL || |
39 | (buf->dont_free && (buf->readonly || buf->parent != NULL)) || | ||
40 | buf->max_size > SSHBUF_SIZE_MAX || | 39 | buf->max_size > SSHBUF_SIZE_MAX || |
41 | buf->alloc > buf->max_size || | 40 | buf->alloc > buf->max_size || |
42 | buf->size > buf->alloc || | 41 | buf->size > buf->alloc || |
@@ -132,23 +131,8 @@ sshbuf_fromb(struct sshbuf *buf) | |||
132 | } | 131 | } |
133 | 132 | ||
134 | void | 133 | void |
135 | sshbuf_init(struct sshbuf *ret) | ||
136 | { | ||
137 | explicit_bzero(ret, sizeof(*ret)); | ||
138 | ret->alloc = SSHBUF_SIZE_INIT; | ||
139 | ret->max_size = SSHBUF_SIZE_MAX; | ||
140 | ret->readonly = 0; | ||
141 | ret->dont_free = 1; | ||
142 | ret->refcount = 1; | ||
143 | if ((ret->cd = ret->d = calloc(1, ret->alloc)) == NULL) | ||
144 | ret->alloc = 0; | ||
145 | } | ||
146 | |||
147 | void | ||
148 | sshbuf_free(struct sshbuf *buf) | 134 | sshbuf_free(struct sshbuf *buf) |
149 | { | 135 | { |
150 | int dont_free = 0; | ||
151 | |||
152 | if (buf == NULL) | 136 | if (buf == NULL) |
153 | return; | 137 | return; |
154 | /* | 138 | /* |
@@ -173,14 +157,12 @@ sshbuf_free(struct sshbuf *buf) | |||
173 | buf->refcount--; | 157 | buf->refcount--; |
174 | if (buf->refcount > 0) | 158 | if (buf->refcount > 0) |
175 | return; | 159 | return; |
176 | dont_free = buf->dont_free; | ||
177 | if (!buf->readonly) { | 160 | if (!buf->readonly) { |
178 | explicit_bzero(buf->d, buf->alloc); | 161 | explicit_bzero(buf->d, buf->alloc); |
179 | free(buf->d); | 162 | free(buf->d); |
180 | } | 163 | } |
181 | explicit_bzero(buf, sizeof(*buf)); | 164 | explicit_bzero(buf, sizeof(*buf)); |
182 | if (!dont_free) | 165 | free(buf); |
183 | free(buf); | ||
184 | } | 166 | } |
185 | 167 | ||
186 | void | 168 | void |