Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack-buffer-overflow in makeswf_append_cpparg() at util/makeswf_util.c:78 when -I and -D arguments are too long. #240

Open
randomssr opened this issue Aug 11, 2022 · 0 comments

Comments

@randomssr
Copy link

When the command has option "I" and option "D", and the total length of its argument exceeds 1024, the stack buffer will overflow. Moreover, more than twice of option "I" or "D" can also trigger the bug.

util/makeswf_util.c
Line 75-79

void
makeswf_append_cpparg(const char* buf)
{
	strncat(cppargs, buf, MAXCPPARGS-1);
}

In main(), makwswf parses option "I" and "D". makwswf_append_cpparg() will be called in both process. It passed its option argument to makeswf_append_cpparg(). However, makeswf can call makwswf_append_cppargs twice. As a result, the stack buffer will overflow when the total length of arguments of "I" and "D" is too long.

Test Environment

Ubuntu 20.04, 64bit
libming(master, 04aee52)

How to trigger

  1. Compile the program with AddressSanitizer
  2. Run command ./makeswf -I BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB -D CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

=================================================================
==3466725==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000000da9060 at pc 0x0000004814b4 bp 0x7ffe0e2d3270 sp 0x7ffe0e2d2a08
WRITE of size 814 at 0x000000da9060 thread T0
    #0 0x4814b3 in strncat (/home/ubuntu20/bug_report/libming/makeswf/crash/makeswf+0x4814b3)
    #1 0x4c8950 in makeswf_append_cpparg /home/ubuntu20/bug_report/libming/makeswf/sourcecode/libming/util/makeswf_utils.c:78:2
    #2 0x4c61e6 in main /home/ubuntu20/bug_report/libming/makeswf/sourcecode/libming/util/makeswf.c:320:5
    #3 0x7faa12051082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #4 0x41d11d in _start (/home/ubuntu20/bug_report/libming/makeswf/crash/makeswf+0x41d11d)

0x000000da9060 is located 0 bytes to the right of global variable 'cppargs' defined in 'makeswf_utils.c:72:13' (0xda8c60) of size 1024
SUMMARY: AddressSanitizer: global-buffer-overflow (/home/ubuntu20/bug_report/libming/makeswf/crash/makeswf+0x4814b3) in strncat
Shadow bytes around the buggy address:
  0x0000801ad1b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad1c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad1d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad1e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad1f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0000801ad200: 00 00 00 00 00 00 00 00 00 00 00 00[f9]f9 f9 f9
  0x0000801ad210: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0000801ad220: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x0000801ad230: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000801ad250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==3466725==ABORTING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant