OSDN Git Service

[fix] #41312 spoil_out 関数におけるバッファオーバーラン
authorHabu <habu@users.sourceforge.jp>
Sat, 23 Jan 2021 02:01:26 +0000 (11:01 +0900)
committerHabu <habu@users.sourceforge.jp>
Sat, 23 Jan 2021 02:04:13 +0000 (11:04 +0900)
参照するフラグを誤っているため、2バイト文字の2バイト目を1バイト目として処理してしまっている。
文字列の最後('\0'の前)が2バイト文字だった場合、バッファの範囲外にアクセスする可能性がある。
正しいフラグを参照するように修正する。

src/wizard/spoiler-util.c

index 73e52e4..ffaf75c 100644 (file)
@@ -114,9 +114,9 @@ void spoil_out(concptr str)
 
         if (!wrap) {
 #ifdef JP
-            if (roff_p >= roff_buf + (k_flag ? 74 : 75))
+            if (roff_p >= roff_buf + (iskanji_flag ? 74 : 75))
                 wrap = TRUE;
-            else if ((ch == ' ') && (roff_p >= roff_buf + (k_flag ? 72 : 73)))
+            else if ((ch == ' ') && (roff_p >= roff_buf + (iskanji_flag ? 72 : 73)))
                 wrap = TRUE;
 #else
             if (roff_p >= roff_buf + 75)
@@ -129,7 +129,7 @@ void spoil_out(concptr str)
 #ifdef JP
                 bool k_flag_local;
                 bool iskanji_flag_local = FALSE;
-                concptr tail = str + (k_flag ? 2 : 1);
+                concptr tail = str + (iskanji_flag ? 2 : 1);
 #else
                 concptr tail = str + 1;
 #endif