buffer.c (146998) | buffer.c (147001) |
---|---|
1/* 2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * All rights reserved 5 * Functions for manipulating fifo buffers (that can grow if needed). 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is 10 * incompatible with the protocol description in the RFC file, it must be 11 * called by a name other than "ssh" or "Secure Shell". 12 */ 13 14#include "includes.h" | 1/* 2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * All rights reserved 5 * Functions for manipulating fifo buffers (that can grow if needed). 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is 10 * incompatible with the protocol description in the RFC file, it must be 11 * called by a name other than "ssh" or "Secure Shell". 12 */ 13 14#include "includes.h" |
15RCSID("$OpenBSD: buffer.c,v 1.22 2004/10/29 23:56:17 djm Exp $"); | 15RCSID("$OpenBSD: buffer.c,v 1.23 2005/03/14 11:46:56 markus Exp $"); |
16 17#include "xmalloc.h" 18#include "buffer.h" 19#include "log.h" 20 21/* Initializes the buffer structure. */ 22 23void --- 49 unchanged lines hidden (view full) --- 73 */ 74 75void * 76buffer_append_space(Buffer *buffer, u_int len) 77{ 78 u_int newlen; 79 void *p; 80 | 16 17#include "xmalloc.h" 18#include "buffer.h" 19#include "log.h" 20 21/* Initializes the buffer structure. */ 22 23void --- 49 unchanged lines hidden (view full) --- 73 */ 74 75void * 76buffer_append_space(Buffer *buffer, u_int len) 77{ 78 u_int newlen; 79 void *p; 80 |
81 if (len > 0x100000) | 81 if (len > BUFFER_MAX_CHUNK) |
82 fatal("buffer_append_space: len %u not supported", len); 83 84 /* If the buffer is empty, start using it from the beginning. */ 85 if (buffer->offset == buffer->end) { 86 buffer->offset = 0; 87 buffer->end = 0; 88 } 89restart: 90 /* If there is enough space to store all data, store it now. */ 91 if (buffer->end + len < buffer->alloc) { 92 p = buffer->buf + buffer->end; 93 buffer->end += len; 94 return p; 95 } 96 /* 97 * If the buffer is quite empty, but all data is at the end, move the 98 * data to the beginning and retry. 99 */ | 82 fatal("buffer_append_space: len %u not supported", len); 83 84 /* If the buffer is empty, start using it from the beginning. */ 85 if (buffer->offset == buffer->end) { 86 buffer->offset = 0; 87 buffer->end = 0; 88 } 89restart: 90 /* If there is enough space to store all data, store it now. */ 91 if (buffer->end + len < buffer->alloc) { 92 p = buffer->buf + buffer->end; 93 buffer->end += len; 94 return p; 95 } 96 /* 97 * If the buffer is quite empty, but all data is at the end, move the 98 * data to the beginning and retry. 99 */ |
100 if (buffer->offset > buffer->alloc / 2) { | 100 if (buffer->offset > MIN(buffer->alloc, BUFFER_MAX_CHUNK)) { |
101 memmove(buffer->buf, buffer->buf + buffer->offset, 102 buffer->end - buffer->offset); 103 buffer->end -= buffer->offset; 104 buffer->offset = 0; 105 goto restart; 106 } 107 /* Increase the size of the buffer and retry. */ 108 109 newlen = buffer->alloc + len + 32768; | 101 memmove(buffer->buf, buffer->buf + buffer->offset, 102 buffer->end - buffer->offset); 103 buffer->end -= buffer->offset; 104 buffer->offset = 0; 105 goto restart; 106 } 107 /* Increase the size of the buffer and retry. */ 108 109 newlen = buffer->alloc + len + 32768; |
110 if (newlen > 0xa00000) | 110 if (newlen > BUFFER_MAX_LEN) |
111 fatal("buffer_append_space: alloc %u not supported", 112 newlen); 113 buffer->buf = xrealloc(buffer->buf, newlen); 114 buffer->alloc = newlen; 115 goto restart; 116 /* NOTREACHED */ 117} 118 --- 93 unchanged lines hidden --- | 111 fatal("buffer_append_space: alloc %u not supported", 112 newlen); 113 buffer->buf = xrealloc(buffer->buf, newlen); 114 buffer->alloc = newlen; 115 goto restart; 116 /* NOTREACHED */ 117} 118 --- 93 unchanged lines hidden --- |