Prevent heap-buffer-overflow in Strnew_size()
Bug-Debian: https://github.com/tats/w3m/issues/72
This commit is contained in:
2
Str.c
2
Str.c
@@ -48,6 +48,8 @@ Str
|
|||||||
Strnew_size(int n)
|
Strnew_size(int n)
|
||||||
{
|
{
|
||||||
Str x = GC_MALLOC(sizeof(struct _Str));
|
Str x = GC_MALLOC(sizeof(struct _Str));
|
||||||
|
if (n < 0)
|
||||||
|
n = 0;
|
||||||
x->ptr = GC_MALLOC_ATOMIC(n + 1);
|
x->ptr = GC_MALLOC_ATOMIC(n + 1);
|
||||||
x->ptr[0] = '\0';
|
x->ptr[0] = '\0';
|
||||||
x->area_size = n + 1;
|
x->area_size = n + 1;
|
||||||
|
Reference in New Issue
Block a user