]> andersk Git - openssh.git/blobdiff - bufaux.c
- djm@cvs.openbsd.org 2010/01/30 02:54:53
[openssh.git] / bufaux.c
index 4c9cb662c3610c09e3ce804b211d97f51d1504a8..e17f001e1c86a11a1d21b50483b16b074d0170a1 100644 (file)
--- a/bufaux.c
+++ b/bufaux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bufaux.c,v 1.42 2006/04/18 10:44:28 dtucker Exp $ */
+/* $OpenBSD: bufaux.c,v 1.47 2010/01/12 01:36:08 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
 
 #include "includes.h"
 
+#include <sys/types.h>
+
 #include <openssl/bn.h>
-#include "bufaux.h"
+
+#include <string.h>
+#include <stdarg.h>
+
 #include "xmalloc.h"
+#include "buffer.h"
 #include "log.h"
 #include "misc.h"
 
@@ -174,7 +180,7 @@ buffer_get_string_ret(Buffer *buffer, u_int *length_ptr)
                return (NULL);
        }
        /* Append a null character to make processing easier. */
-       value[len] = 0;
+       value[len] = '\0';
        /* Optionally return the length of the string. */
        if (length_ptr)
                *length_ptr = len;
@@ -191,6 +197,35 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr)
        return (ret);
 }
 
+void *
+buffer_get_string_ptr_ret(Buffer *buffer, u_int *length_ptr)
+{
+       void *ptr;
+       u_int len;
+
+       if (buffer_get_int_ret(&len, buffer) != 0)
+               return NULL;
+       if (len > 256 * 1024) {
+               error("buffer_get_string_ptr: bad string length %u", len);
+               return NULL;
+       }
+       ptr = buffer_ptr(buffer);
+       buffer_consume(buffer, len);
+       if (length_ptr)
+               *length_ptr = len;
+       return (ptr);
+}
+
+void *
+buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr)
+{
+       void *ret;
+
+       if ((ret = buffer_get_string_ptr_ret(buffer, length_ptr)) == NULL)
+               fatal("buffer_get_string_ptr: buffer error");
+       return (ret);
+}
+
 /*
  * Stores and arbitrary binary string in the buffer.
  */
This page took 0.19671 seconds and 4 git commands to generate.