]> andersk Git - gssapi-openssh.git/blobdiff - openssh/buffer.c
added note that we added GT 3.2b compatibility in this release
[gssapi-openssh.git] / openssh / buffer.c
index 40572e5ac30e5c4e5e6ee8ced39b025377b78a8f..9217cb2695cf9ad68be4545b4d76ab9fced181d4 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: buffer.c,v 1.15 2002/01/18 18:14:17 stevesk Exp $");
+RCSID("$OpenBSD: buffer.c,v 1.21 2003/11/21 11:57:03 djm Exp $");
 
 #include "xmalloc.h"
 #include "buffer.h"
@@ -23,8 +23,11 @@ RCSID("$OpenBSD: buffer.c,v 1.15 2002/01/18 18:14:17 stevesk Exp $");
 void
 buffer_init(Buffer *buffer)
 {
-       buffer->alloc = 4096;
-       buffer->buf = xmalloc(buffer->alloc);
+       const u_int len = 4096;
+
+       buffer->alloc = 0;
+       buffer->buf = xmalloc(len);
+       buffer->alloc = len;
        buffer->offset = 0;
        buffer->end = 0;
 }
@@ -34,8 +37,11 @@ buffer_init(Buffer *buffer)
 void
 buffer_free(Buffer *buffer)
 {
-       memset(buffer->buf, 0, buffer->alloc);
-       xfree(buffer->buf);
+       if (buffer->alloc > 0) {
+               memset(buffer->buf, 0, buffer->alloc);
+               buffer->alloc = 0;
+               xfree(buffer->buf);
+       }
 }
 
 /*
@@ -69,8 +75,12 @@ buffer_append(Buffer *buffer, const void *data, u_int len)
 void *
 buffer_append_space(Buffer *buffer, u_int len)
 {
+       u_int newlen;
        void *p;
 
+       if (len > 0x100000)
+               fatal("buffer_append_space: len %u not supported", len);
+
        /* If the buffer is empty, start using it from the beginning. */
        if (buffer->offset == buffer->end) {
                buffer->offset = 0;
@@ -95,8 +105,13 @@ restart:
                goto restart;
        }
        /* Increase the size of the buffer and retry. */
-       buffer->alloc += len + 32768;
-       buffer->buf = xrealloc(buffer->buf, buffer->alloc);
+
+       newlen = buffer->alloc + len + 32768;
+       if (newlen > 0xa00000)
+               fatal("buffer_append_space: alloc %u not supported",
+                   newlen);
+       buffer->buf = xrealloc(buffer->buf, newlen);
+       buffer->alloc = newlen;
        goto restart;
        /* NOTREACHED */
 }
@@ -154,7 +169,7 @@ buffer_ptr(Buffer *buffer)
 void
 buffer_dump(Buffer *buffer)
 {
-       int i;
+       u_int i;
        u_char *ucp = buffer->buf;
 
        for (i = buffer->offset; i < buffer->end; i++) {
This page took 0.428835 seconds and 4 git commands to generate.