mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
string: Don't allow to allocate strings bigger than 256M
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
(cherry picked from commit f48dcb26e3)
This commit is contained in:
@@ -34,6 +34,9 @@
|
|||||||
#include "libssh/priv.h"
|
#include "libssh/priv.h"
|
||||||
#include "libssh/string.h"
|
#include "libssh/string.h"
|
||||||
|
|
||||||
|
/* String maximum size is 256M */
|
||||||
|
#define STRING_SIZE_MAX 0x10000000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup libssh_string The SSH string functions
|
* @defgroup libssh_string The SSH string functions
|
||||||
* @ingroup libssh
|
* @ingroup libssh
|
||||||
@@ -54,7 +57,8 @@ struct ssh_string_struct *ssh_string_new(size_t size)
|
|||||||
{
|
{
|
||||||
struct ssh_string_struct *str = NULL;
|
struct ssh_string_struct *str = NULL;
|
||||||
|
|
||||||
if (size > UINT_MAX - sizeof(struct ssh_string_struct)) {
|
if (size > STRING_SIZE_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +141,7 @@ size_t ssh_string_len(struct ssh_string_struct *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = ntohl(s->size);
|
size = ntohl(s->size);
|
||||||
if (size > 0 && size < UINT_MAX) {
|
if (size > 0 && size <= STRING_SIZE_MAX) {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user