assert error when memory allocation failed
This commit is contained in:
parent
4a94f3fc12
commit
a87460e280
109
yajl-assert-error-when-memory-allocation-failed.patch
Normal file
109
yajl-assert-error-when-memory-allocation-failed.patch
Normal file
@ -0,0 +1,109 @@
|
||||
From 941bc5f96825e9178b8354cf16b033fb61221021 Mon Sep 17 00:00:00 2001
|
||||
From: Ruoshu Gao <gaoruoshu@huawei.com>
|
||||
Date: Thu, 8 Sep 2022 19:15:58 +0800
|
||||
Subject: [PATCH] yajl: assert error when memory allocation failed
|
||||
|
||||
Signed-off-by: Ruoshu Gao <gaoruoshu@huawei.com>
|
||||
---
|
||||
src/yajl.c | 2 ++
|
||||
src/yajl_buf.c | 3 +++
|
||||
src/yajl_bytestack.h | 2 ++
|
||||
src/yajl_lex.c | 1 +
|
||||
test/parsing/yajl_test.c | 1 +
|
||||
5 files changed, 9 insertions(+)
|
||||
|
||||
diff --git a/src/yajl.c b/src/yajl.c
|
||||
index d477893..c0f3094 100644
|
||||
--- a/src/yajl.c
|
||||
+++ b/src/yajl.c
|
||||
@@ -62,6 +62,7 @@ yajl_alloc(const yajl_callbacks * callbacks,
|
||||
}
|
||||
|
||||
hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
|
||||
+ if (!hand) abort();
|
||||
|
||||
/* copy in pointers to allocation routines */
|
||||
memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
|
||||
@@ -145,6 +146,7 @@ yajl_complete_parse(yajl_handle hand)
|
||||
hand->lexer = yajl_lex_alloc(&(hand->alloc),
|
||||
hand->flags & yajl_allow_comments,
|
||||
!(hand->flags & yajl_dont_validate_strings));
|
||||
+ if (!hand->lexer) abort();
|
||||
}
|
||||
|
||||
return yajl_do_finish(hand);
|
||||
diff --git a/src/yajl_buf.c b/src/yajl_buf.c
|
||||
index 1aeafde..5556a17 100644
|
||||
--- a/src/yajl_buf.c
|
||||
+++ b/src/yajl_buf.c
|
||||
@@ -40,6 +40,7 @@ void yajl_buf_ensure_available(yajl_buf buf, size_t want)
|
||||
if (buf->data == NULL) {
|
||||
buf->len = YAJL_BUF_INIT_SIZE;
|
||||
buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len);
|
||||
+ if (!buf->data) abort();
|
||||
buf->data[0] = 0;
|
||||
}
|
||||
|
||||
@@ -49,6 +50,7 @@ void yajl_buf_ensure_available(yajl_buf buf, size_t want)
|
||||
|
||||
if (need != buf->len) {
|
||||
buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);
|
||||
+ if (!buf->data) abort();
|
||||
buf->len = need;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +58,7 @@ void yajl_buf_ensure_available(yajl_buf buf, size_t want)
|
||||
yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc)
|
||||
{
|
||||
yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t));
|
||||
+ if (!b) abort();
|
||||
memset((void *) b, 0, sizeof(struct yajl_buf_t));
|
||||
b->alloc = alloc;
|
||||
return b;
|
||||
diff --git a/src/yajl_bytestack.h b/src/yajl_bytestack.h
|
||||
index 9ea7d15..1072081 100644
|
||||
--- a/src/yajl_bytestack.h
|
||||
+++ b/src/yajl_bytestack.h
|
||||
@@ -23,6 +23,7 @@
|
||||
#define __YAJL_BYTESTACK_H__
|
||||
|
||||
#include "api/yajl_common.h"
|
||||
+#include <stdlib.h>
|
||||
|
||||
#define YAJL_BS_INC 128
|
||||
|
||||
@@ -56,6 +57,7 @@ typedef struct yajl_bytestack_t
|
||||
(obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\
|
||||
(void *) (obs).stack, (obs).size);\
|
||||
} \
|
||||
+ if (!(obs).stack) abort(); \
|
||||
(obs).stack[((obs).used)++] = (byte); \
|
||||
}
|
||||
|
||||
diff --git a/src/yajl_lex.c b/src/yajl_lex.c
|
||||
index 0b6f7cc..a08e703 100644
|
||||
--- a/src/yajl_lex.c
|
||||
+++ b/src/yajl_lex.c
|
||||
@@ -105,6 +105,7 @@ yajl_lex_alloc(yajl_alloc_funcs * alloc,
|
||||
unsigned int allowComments, unsigned int validateUTF8)
|
||||
{
|
||||
yajl_lexer lxr = (yajl_lexer) YA_MALLOC(alloc, sizeof(struct yajl_lexer_t));
|
||||
+ if (!lxr) abort();
|
||||
memset((void *) lxr, 0, sizeof(struct yajl_lexer_t));
|
||||
lxr->buf = yajl_buf_alloc(alloc);
|
||||
lxr->allowComments = allowComments;
|
||||
diff --git a/test/parsing/yajl_test.c b/test/parsing/yajl_test.c
|
||||
index c50755b..8d67ed9 100644
|
||||
--- a/test/parsing/yajl_test.c
|
||||
+++ b/test/parsing/yajl_test.c
|
||||
@@ -102,6 +102,7 @@ static int test_yajl_map_key(void *ctx, const unsigned char * stringVal,
|
||||
size_t stringLen)
|
||||
{
|
||||
char * str = (char *) malloc(stringLen + 1);
|
||||
+ if (!str) abort();
|
||||
str[stringLen] = 0;
|
||||
memcpy(str, stringVal, stringLen);
|
||||
printf("key: '%s'\n", str);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: yajl
|
||||
Version: 2.1.0
|
||||
Release: 17
|
||||
Release: 18
|
||||
Summary: Yet Another JSON Library
|
||||
License: ISC
|
||||
URL: http://lloyd.github.com/yajl/
|
||||
@ -14,6 +14,7 @@ Patch5: 0005-yajl-2.1.0-fix-memory-leak.patch
|
||||
Patch6: 0006-fix-memory-leak-of-ctx-root.patch
|
||||
Patch7: 0007-add-cmake-option-for-test-and-binary.patch
|
||||
Patch8: backport-CVE-2022-24795.patch
|
||||
Patch9: yajl-assert-error-when-memory-allocation-failed.patch
|
||||
|
||||
BuildRequires: cmake gcc
|
||||
|
||||
@ -70,6 +71,9 @@ cd ../api
|
||||
%{_libdir}/libyajl_s.a
|
||||
|
||||
%changelog
|
||||
* Fri Sep 9 2022 panxiaohe <panxh.life@foxmail.com> - 2.1.0-18
|
||||
- assert error when memory allocation failed
|
||||
|
||||
* Fri Sep 9 2022 panxiaohe <panxh.life@foxmail.com> - 2.1.0-17
|
||||
- fix CVE-2022-24795
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user