|
|
22c622 |
From ad3a19e6372b1e667128ed1ea2f49919884587e1 Mon Sep 17 00:00:00 2001
|
|
|
22c622 |
From: Akira TAGOH <akira@tagoh.org>
|
|
|
22c622 |
Date: Thu, 17 Feb 2022 17:30:12 +0900
|
|
|
22c622 |
Subject: [PATCH] Fix the stack buffer overflow issue
|
|
|
22c622 |
|
|
|
22c622 |
strlen() could returns 0. Without a conditional check for len,
|
|
|
22c622 |
accessing S_ pointer with len - 1 may causes a stack buffer overflow.
|
|
|
22c622 |
|
|
|
22c622 |
AddressSanitizer reports this like:
|
|
|
22c622 |
==1219243==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdce043c1f at pc 0x000000403547 bp 0x7ffdce0
|
|
|
22c622 |
43b30 sp 0x7ffdce043b28
|
|
|
22c622 |
READ of size 1 at 0x7ffdce043c1f thread T0
|
|
|
22c622 |
#0 0x403546 in main ../bin/fribidi-main.c:393
|
|
|
22c622 |
#1 0x7f226804e58f in __libc_start_call_main (/lib64/libc.so.6+0x2d58f)
|
|
|
22c622 |
#2 0x7f226804e648 in __libc_start_main_impl (/lib64/libc.so.6+0x2d648)
|
|
|
22c622 |
#3 0x4036f4 in _start (/tmp/fribidi/build/bin/fribidi+0x4036f4)
|
|
|
22c622 |
|
|
|
22c622 |
Address 0x7ffdce043c1f is located in stack of thread T0 at offset 63 in frame
|
|
|
22c622 |
#0 0x4022bf in main ../bin/fribidi-main.c:193
|
|
|
22c622 |
|
|
|
22c622 |
This frame has 5 object(s):
|
|
|
22c622 |
[32, 36) 'option_index' (line 233)
|
|
|
22c622 |
[48, 52) 'base' (line 386)
|
|
|
22c622 |
[64, 65064) 'S_' (line 375) <== Memory access at offset 63 underflows this variable
|
|
|
22c622 |
[65328, 130328) 'outstring' (line 385)
|
|
|
22c622 |
[130592, 390592) 'logical' (line 384)
|
|
|
22c622 |
|
|
|
22c622 |
This fixes https://github.com/fribidi/fribidi/issues/181
|
|
|
22c622 |
---
|
|
|
22c622 |
bin/fribidi-main.c | 2 +-
|
|
|
22c622 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
22c622 |
|
|
|
22c622 |
diff --git a/bin/fribidi-main.c b/bin/fribidi-main.c
|
|
|
22c622 |
index 3cf9fe1..3ae4fb6 100644
|
|
|
22c622 |
--- a/bin/fribidi-main.c
|
|
|
22c622 |
+++ b/bin/fribidi-main.c
|
|
|
22c622 |
@@ -390,7 +390,7 @@ FRIBIDI_END_IGNORE_DEPRECATIONS
|
|
|
22c622 |
S_[sizeof (S_) - 1] = 0;
|
|
|
22c622 |
len = strlen (S_);
|
|
|
22c622 |
/* chop */
|
|
|
22c622 |
- if (S_[len - 1] == '\n')
|
|
|
22c622 |
+ if (len > 0 && S_[len - 1] == '\n')
|
|
|
22c622 |
{
|
|
|
22c622 |
len--;
|
|
|
22c622 |
S_[len] = '\0';
|