summaryrefslogtreecommitdiff
path: root/bufaux.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2010-08-31 22:36:39 +1000
committerDamien Miller <djm@mindrot.org>2010-08-31 22:36:39 +1000
commitda108ece6843f1268aa36d7c8ed0030dc53acd15 (patch)
tree66638a1716374a8d1ac8ece95dceea56ce231a5c /bufaux.c
parentd96546f5b0f7c57395a338dbb9ac3ac5a48b77fa (diff)
- djm@cvs.openbsd.org 2010/08/31 09:58:37
[auth-options.c auth1.c auth2.c bufaux.c buffer.h kex.c key.c packet.c] [packet.h ssh-dss.c ssh-rsa.c] Add buffer_get_cstring() and related functions that verify that the string extracted from the buffer contains no embedded \0 characters* This prevents random (possibly malicious) crap from being appended to strings where it would not be noticed if the string is used with a string(3) function. Use the new API in a few sensitive places. * actually, we allow a single one at the end of the string for now because we don't know how many deployed implementations get this wrong, but don't count on this to remain indefinitely.
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{