summaryrefslogtreecommitdiff
path: root/bufaux.c
diff options
context:
space:
mode:
Diffstat (limited to 'bufaux.c')
-rw-r--r--bufaux.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/bufaux.c b/bufaux.c
index 854fd510a..00208ca27 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bufaux.c,v 1.49 2010/03/26 03:13:17 djm Exp $ */ 1/* $OpenBSD: bufaux.c,v 1.50 2010/08/31 09:58:37 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
@@ -202,6 +202,39 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr)
202 return (ret); 202 return (ret);
203} 203}
204 204
205char *
206buffer_get_cstring_ret(Buffer *buffer, u_int *length_ptr)
207{
208 u_int length;
209 char *cp, *ret = buffer_get_string_ret(buffer, &length);
210
211 if (ret == NULL)
212 return NULL;
213 if ((cp = memchr(ret, '\0', length)) != NULL) {
214 /* XXX allow \0 at end-of-string for a while, remove later */
215 if (cp == ret + length - 1)
216 error("buffer_get_cstring_ret: string contains \\0");
217 else {
218 bzero(ret, length);
219 xfree(ret);
220 return NULL;
221 }
222 }
223 if (length_ptr != NULL)
224 *length_ptr = length;
225 return ret;
226}
227
228char *
229buffer_get_cstring(Buffer *buffer, u_int *length_ptr)
230{
231 char *ret;
232
233 if ((ret = buffer_get_cstring_ret(buffer, length_ptr)) == NULL)
234 fatal("buffer_get_cstring: buffer error");
235 return ret;
236}
237
205void * 238void *
206buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr) 239buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr)
207{ 240{