[LLVMbugs] [Bug 8847] New: ocaml bindings: exception raising broken causes segfault

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Dec 23 04:31:32 PST 2010


http://llvm.org/bugs/show_bug.cgi?id=8847

           Summary: ocaml bindings: exception raising broken causes
                    segfault
           Product: new-bugs
           Version: 2.8
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: edwintorok at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Trying to open an invalid bitcode file with bitreader using the OCaml bindings
causes a segfault, instead of raising an exception with "Invalid bitcode
signature".

OCaml should probably check that the raised exception is not NULL instead of
trusting the C binding blindly, but then the LLVM bindings shouldn't send NULL
exceptions either.

Testcase:
$ cat p.ml
open Llvm
open Llvm_bitreader

let context = global_context ()

let the_module = get_module context (MemoryBuffer.of_stdin ())

$ ocamlc  -I ../obj/Release/lib/ocaml llvm.cma llvm_bitreader.cma p.ml -cc g++
-o p
$ ./p </dev/null
Segmentation fault

$ valgrind ./p </dev/null
==16485== Invalid read of size 8
==16485==    at 0x50D887: caml_format_exception (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x50DA0B: caml_fatal_uncaught_exception (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x51D53A: caml_main (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x51A7FF: main (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==16485== 
==16485== 
==16485== Process terminating with default action of signal 11 (SIGSEGV)
==16485==  Access not within mapped region at address 0x0
==16485==    at 0x50D887: caml_format_exception (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x50DA0B: caml_fatal_uncaught_exception (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x51D53A: caml_main (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==    by 0x51A7FF: main (in
/home/edwin/clam/git/bytecode/clamav-bytecode-compiler2/src/p)
==16485==  If you believe this happened as a result of a stack
==16485==  overflow in your program's main thread (unlikely but
==16485==  possible), you can try to increase the size of the
==16485==  main thread stack using the --main-stacksize= flag.
==16485==  The main thread stack size used in this run was 8388608.

$ ocamlc -config
version: 3.11.2
standard_library_default: /usr/lib/ocaml
standard_library: /usr/lib/ocaml
standard_runtime: /usr/bin/ocamlrun
ccomp_type: cc
bytecomp_c_compiler: gcc -fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64
-D_REENTRANT -fPIC
bytecomp_c_libraries: -lm  -ldl -lcurses -lpthread
native_c_compiler: gcc -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT
native_c_libraries: -lm  -ldl
native_pack_linker: ld -r  -o 
ranlib: ranlib
cc_profile: -pg
architecture: amd64
model: default
system: linux
asm: as
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list