Mercurial > dropbear
comparison buffer.c @ 118:5312ca05ed48 private-rez
propagate of 717950f4061f1123659ee87c7c168805af920ab7 and 839f98f136788cc1466e4641bf796f96040a085d from branch 'matt.dbclient.authpam' to 'matt.dbclient.rez'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 12 Sep 2004 04:56:50 +0000 |
parents | 10f4d3319780 |
children | 0cfba3034be5 |
comparison
equal
deleted
inserted
replaced
57:3b2a5a1c4347 | 118:5312ca05ed48 |
---|---|
1 /* | 1 /* |
2 * Dropbear - a SSH2 server | 2 * Dropbear SSH |
3 * | 3 * |
4 * Copyright (c) 2002,2003 Matt Johnston | 4 * Copyright (c) 2002,2003 Matt Johnston |
5 * All rights reserved. | 5 * All rights reserved. |
6 * | 6 * |
7 * Permission is hereby granted, free of charge, to any person obtaining a copy | 7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
32 * Calling functions should check arguments first, but this provides a | 32 * Calling functions should check arguments first, but this provides a |
33 * backstop */ | 33 * backstop */ |
34 #define BUF_MAX_INCR 1000000000 | 34 #define BUF_MAX_INCR 1000000000 |
35 #define BUF_MAX_SIZE 1000000000 | 35 #define BUF_MAX_SIZE 1000000000 |
36 | 36 |
37 /* avoid excessively large numbers, > 5000 bit */ | 37 /* avoid excessively large numbers, > ~8192 bits */ |
38 #define BUF_MAX_MPINT (5000 / 8) | 38 #define BUF_MAX_MPINT (8240 / 8) |
39 | 39 |
40 /* Create (malloc) a new buffer of size */ | 40 /* Create (malloc) a new buffer of size */ |
41 buffer* buf_new(unsigned int size) { | 41 buffer* buf_new(unsigned int size) { |
42 | 42 |
43 buffer* buf; | 43 buffer* buf; |
74 | 74 |
75 m_burn(buf->data, buf->size); | 75 m_burn(buf->data, buf->size); |
76 | 76 |
77 } | 77 } |
78 | 78 |
79 /* resize a buffer, pos and len will be repositioned if required */ | 79 /* resize a buffer, pos and len will be repositioned if required when |
80 * downsizing */ | |
80 void buf_resize(buffer *buf, unsigned int newsize) { | 81 void buf_resize(buffer *buf, unsigned int newsize) { |
81 | 82 |
82 if (newsize > BUF_MAX_SIZE) { | 83 if (newsize > BUF_MAX_SIZE) { |
83 dropbear_exit("buf->size too big"); | 84 dropbear_exit("buf->size too big"); |
84 } | 85 } |
149 } | 150 } |
150 | 151 |
151 /* Get a byte from the buffer and increment the pos */ | 152 /* Get a byte from the buffer and increment the pos */ |
152 unsigned char buf_getbyte(buffer* buf) { | 153 unsigned char buf_getbyte(buffer* buf) { |
153 | 154 |
155 /* This check is really just ==, but the >= allows us to check for the | |
156 * assert()able case of pos > len, which should _never_ happen. */ | |
154 if (buf->pos >= buf->len) { | 157 if (buf->pos >= buf->len) { |
155 dropbear_exit("bad buf_getbyte"); | 158 dropbear_exit("bad buf_getbyte"); |
156 } | 159 } |
157 return buf->data[buf->pos++]; | 160 return buf->data[buf->pos++]; |
158 } | 161 } |