diff --git a/yajl-assert-error-when-memory-allocation-failed.patch b/yajl-assert-error-when-memory-allocation-failed.patch new file mode 100644 index 0000000000000000000000000000000000000000..6127db2966cbc6261b4c3a0ee1d4027949f6d19a --- /dev/null +++ b/yajl-assert-error-when-memory-allocation-failed.patch @@ -0,0 +1,109 @@ +From 941bc5f96825e9178b8354cf16b033fb61221021 Mon Sep 17 00:00:00 2001 +From: Ruoshu Gao +Date: Thu, 8 Sep 2022 19:15:58 +0800 +Subject: [PATCH] yajl: assert error when memory allocation failed + +Signed-off-by: Ruoshu Gao +--- + 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 + + #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 + diff --git a/yajl.spec b/yajl.spec index 09f99acb34eefbfb871466a85087c78b6313b363..9e3ef34a257cee946ae0966d725e51c35c903fef 100644 --- a/yajl.spec +++ b/yajl.spec @@ -1,6 +1,6 @@ Name: yajl Version: 2.1.0 -Release: 15 +Release: 16 Summary: Yet Another JSON Library License: ISC URL: http://lloyd.github.com/yajl/ @@ -13,6 +13,7 @@ Patch4: yajl-2.1.0-dynlink-binaries.patch Patch5: yajl-2.1.0-fix-memory-leak.patch Patch6: backport-fix-memory-leaks.patch Patch7: backport-CVE-2022-24795.patch +Patch8: yajl-assert-error-when-memory-allocation-failed.patch BuildRequires: cmake gcc @@ -69,6 +70,9 @@ cd ../api %{_libdir}/libyajl_s.a %changelog +* Fri Sep 9 2022 panxiaohe - 2.1.0-16 +- assert error when memory allocation failed + * Fri Sep 9 2022 panxiaohe - 2.1.0-15 - fix CVE-2022-24795