From a1334b1fe5a033a175d1fc28b813d286651a7a0a Mon Sep 17 00:00:00 2001 From: Choe Hwanjin Date: Sun, 19 Dec 2021 16:03:42 +0900 Subject: hanja: Fix dereference of NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Static Analysis에서 발견된 "dereference of NULL" 문제를 수정한다. HanjaList 메모리 할당에 실패한 경우에 대한 처리가 되지 않고 있었다. list 할당에 실패한 경우 Hanja 아이템을 추가하지 않게 한다. https://github.com/libhangul/libhangul/issues/53 --- hangul/hanja.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hangul/hanja.c b/hangul/hanja.c index 0cc7349..0cbe347 100644 --- a/hangul/hanja.c +++ b/hangul/hanja.c @@ -436,15 +436,19 @@ hanja_table_match(const HanjaTable* table, char* p = strtok_r(buf, ":", &save); res = strcmp(p, key); if (res == 0) { + if (*list == NULL) { + *list = hanja_list_new(key); + } + + if (*list == NULL) { + break; + } + char* value = strtok_r(NULL, ":", &save); char* comment = strtok_r(NULL, "\r\n", &save); Hanja* hanja = hanja_new(p, value, comment); - if (*list == NULL) { - *list = hanja_list_new(key); - } - hanja_list_append_n(*list, hanja, 1); } else if (res > 0) { break; -- cgit v1.2.1