From a65e9d344738f53a79f4325ad967556bb56518bc Mon Sep 17 00:00:00 2001 From: NOKUBI Takatsugu Date: Thu, 14 Jun 2012 16:49:11 +0900 Subject: [PATCH] Fix buffer overflow --- ChangeLog | 6 ++++++ lib/chalib.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e600b34..58bc140 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-06-14 NOKUBI Takatsugu + + * lib/chalib.c (chasen_sparse_main): + fix buffer overflow + JVN#16901583 https://jvn.jp/jp/JVN16901583/index.html + 2007-07-23 Asahara Masayuki * lib/tokenizer.c (cha_tok_parse): diff --git a/lib/chalib.c b/lib/chalib.c index 5d79e13..cddf51b 100644 --- a/lib/chalib.c +++ b/lib/chalib.c @@ -306,9 +306,14 @@ chasen_sparse_main(char *input, FILE *output) */ while (*input) { int c = 0, len, cursor; - if ((crlf = strpbrk(input, "\r\n")) == NULL) + if ((crlf = strpbrk(input, "\r\n")) == NULL) { len = strlen(input); - else { + if (len >= CHA_INPUT_SIZE) { + len = CHA_INPUT_SIZE - 1; + crlf = input + CHA_INPUT_SIZE - 2; + c = 0; + } + } else { len = crlf - input; c = *crlf; *crlf = '\0';