summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChoe Hwanjin <choe.hwanjin@gmail.com>2021-12-19 16:03:42 +0900
committerChoe Hwanjin <choe.hwanjin@gmail.com>2021-12-19 16:03:42 +0900
commita1334b1fe5a033a175d1fc28b813d286651a7a0a (patch)
tree9c0e1be4799511293c5960a4d6db714a4944b1b1
parent8255f32704a03ca131df2b7d139bf62cf2d4e9e4 (diff)
downloadlibhangul-static-analysis.tar.gz
hanja: Fix dereference of NULLstatic-analysis
Static Analysis에서 발견된 "dereference of NULL" 문제를 수정한다. HanjaList 메모리 할당에 실패한 경우에 대한 처리가 되지 않고 있었다. list 할당에 실패한 경우 Hanja 아이템을 추가하지 않게 한다. https://github.com/libhangul/libhangul/issues/53
-rw-r--r--hangul/hanja.c12
1 files 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;