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

heap-buffer-overflow in /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:301 ok_mo_decode2() #6

Closed
moonAgirl opened this Issue Dec 31, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@moonAgirl
Copy link

moonAgirl commented Dec 31, 2018

Test Version

dev version, git clone https://github.com/brackeen/ok-file-formats.git

Test Program

#include <stdio.h>
#include "ok_mo.h"

int main(int _argc, char **_argv) {
    FILE *file = fopen(_argv[1], "rb");
    ok_mo *image = ok_mo_read(file);
    fclose(file);
    ok_mo_free(image);
    return 0;
}

$ gcc -o mo_decode mo_decode.c ok_mo.h ok_mo.c

Asan Debug Information

➜  ok-file-formats git:(master) ✗ ./mo_decode-asan ./mo_out/03-heap-buffer-overflow.mo 
=================================================================
==31120==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000ef71 at pc 0x0000004058ae bp 0x7ffc8b9cb940 sp 0x7ffc8b9cb930
READ of size 1 at 0x60200000ef71 thread T0
    #0 0x4058ad in ok_mo_decode2 /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:301
    #1 0x4058ad in ok_mo_decode /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:96
    #2 0x4058ad in ok_mo_read /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:145
    #3 0x401074 in main /home/moonagirl/megic_afl/ok-file-formats/mo_decode.c:6
    #4 0x7f526eb0c82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #5 0x4011c8 in _start (/home/moonagirl/megic_afl/ok-file-formats/mo_decode-asan+0x4011c8)

0x60200000ef71 is located 0 bytes to the right of 1-byte region [0x60200000ef70,0x60200000ef71)
allocated by thread T0 here:
    #0 0x7f526ef4e602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x40511b in ok_mo_decode2 /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:285
    #2 0x40511b in ok_mo_decode /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:96
    #3 0x40511b in ok_mo_read /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:145

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/moonagirl/megic_afl/ok-file-formats/ok_mo.c:301 ok_mo_decode2
Shadow bytes around the buggy address:
  0x0c047fff9d90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9da0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9db0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9dc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9dd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c047fff9de0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa[01]fa
  0x0c047fff9df0: fa fa 00 fa fa fa 01 fa fa fa 00 00 fa fa 00 00
  0x0c047fff9e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9e30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==31120==ABORTING

POC file

https://github.com/moonAgirl/Bugs/blob/master/ok-file-formats/2018-12-31-03-heap-buffer-overflow.mo

@moonAgirl moonAgirl closed this Jan 3, 2019

brackeen added a commit that referenced this issue Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment