diff options
author | Darren Tucker <dtucker@zip.com.au> | 2010-01-12 19:45:59 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2010-01-12 19:45:59 +1100 |
commit | ebc71d908cc10cafea05e1aaaa7886d3f8b0bf80 (patch) | |
tree | f8a6baaf719a0e3679a1fe5408f6af91b2554f9f /bufaux.c | |
parent | 1b0c2455daf26b9eca30210f7628b7e4667501ad (diff) |
- djm@cvs.openbsd.org 2010/01/12 01:36:08
[buffer.h bufaux.c]
add a buffer_get_string_ptr_ret() that does the same as
buffer_get_string_ptr() but does not fatal() on error; ok dtucker@
Diffstat (limited to 'bufaux.c')
-rw-r--r-- | bufaux.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bufaux.c,v 1.46 2008/06/10 23:21:34 dtucker Exp $ */ | 1 | /* $OpenBSD: bufaux.c,v 1.47 2010/01/12 01:36:08 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -198,14 +198,17 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr) | |||
198 | } | 198 | } |
199 | 199 | ||
200 | void * | 200 | void * |
201 | buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) | 201 | buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr) |
202 | { | 202 | { |
203 | void *ptr; | 203 | void *ptr; |
204 | u_int len; | 204 | u_int len; |
205 | 205 | ||
206 | len = buffer_get_int(buffer); | 206 | if (buffer_get_int_ret(&len, buffer) != 0) |
207 | if (len > 256 * 1024) | 207 | return NULL; |
208 | fatal("buffer_get_string_ptr: bad string length %u", len); | 208 | if (len > 256 * 1024) { |
209 | error("buffer_get_string_ptr: bad string length %u", len); | ||
210 | return NULL; | ||
211 | } | ||
209 | ptr = buffer_ptr(buffer); | 212 | ptr = buffer_ptr(buffer); |
210 | buffer_consume(buffer, len); | 213 | buffer_consume(buffer, len); |
211 | if (length_ptr) | 214 | if (length_ptr) |
@@ -213,6 +216,16 @@ buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) | |||
213 | return (ptr); | 216 | return (ptr); |
214 | } | 217 | } |
215 | 218 | ||
219 | void * | ||
220 | buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr) | ||
221 | { | ||
222 | void *ret; | ||
223 | |||
224 | if ((ret = buffer_get_string_ptr_ret(buffer, length_ptr)) == NULL) | ||
225 | fatal("buffer_get_string_ptr: buffer error"); | ||
226 | return (ret); | ||
227 | } | ||
228 | |||
216 | /* | 229 | /* |
217 | * Stores and arbitrary binary string in the buffer. | 230 | * Stores and arbitrary binary string in the buffer. |
218 | */ | 231 | */ |