1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-07 08:02:55 +03:00

CVE-2012-4562: Fix a possible infinite loop in buffer_reinit().

If needed is bigger than the highest power of two or a which fits in an
integer we will loop forever.
This commit is contained in:
Andreas Schneider
2012-10-12 11:35:20 +02:00
parent ad5f306884
commit f61813eaea

View File

@@ -111,13 +111,18 @@ void ssh_buffer_free(struct ssh_buffer_struct *buffer) {
SAFE_FREE(buffer);
}
static int realloc_buffer(struct ssh_buffer_struct *buffer, int needed) {
int smallest = 1;
char *new = NULL;
static int realloc_buffer(struct ssh_buffer_struct *buffer, size_t needed) {
size_t smallest = 1;
char *new;
buffer_verify(buffer);
/* Find the smallest power of two which is greater or equal to needed */
while(smallest <= needed) {
smallest <<= 1;
if (smallest == 0) {
return -1;
}
smallest <<= 1;
}
needed = smallest;
new = realloc(buffer->data, needed);