Report bug in GMP library.

Thông Nguyễn Văn anhthong.381996 at gmail.com
Fri Feb 24 05:23:55 UTC 2017


Hello, development team.

I have found a bug in GMP library when I were using mpz_inits(x,y) function.

+) GMP-6.1.2

+) This is my program:
// g++  test.cpp -c
// g++ -o test test.o -lgmp
// ./test

#include <gmp.h>

int main()
{
mpz_t x,y;
mpz_inits(x,y);  // use "mpz_init(x);mpz_init(y);" to get correct.
}

+) I have run this program and get a Segmentation fault (core dumped).

+) stack backtrace:
gdb-peda$ where
#0  0xb7f56444 in __gmpz_init () from /usr/lib/i386-linux-gnu/libgmp.so.10
#1  0xb7f564eb in __gmpz_inits () from /usr/lib/i386-linux-gnu/libgmp.so.10
#2  0x0804856a in main ()
#3  0xb7da7af3 in __libc_start_main (main=0x804854d <main>, argc=0x1,
    argv=0xbffff1e4, init=0x8048580 <__libc_csu_init>,
    fini=0x80485f0 <__libc_csu_fini>, rtld_fini=0xb7fed160 <_dl_fini>,
    stack_end=0xbffff1dc) at libc-start.c:287
#4  0x08048471 in _start ()

+) strace:
thong at ubuntu:~/Desktop$ strace ./test
execve("./test", ["./test"], [/* 60 vars */]) = 0
brk(0)                                  = 0x895c000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb76f1000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=87672, ...}) = 0
mmap2(NULL, 87672, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76db000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
open("/usr/lib/i386-linux-gnu/libgmp.so.10", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0@\235\0\0004\0\0\0"...,
512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=542600, ...}) = 0
mmap2(NULL, 541264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) =
0xb7656000
mmap2(0xb76d3000, 32768, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7d000) = 0xb76d3000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or
directory)
open("/lib/i386-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3,
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0P\234\1\0004\0\0\0"...,
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1754876, ...}) = 0
mmap2(NULL, 1763964, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0xb74a7000
mprotect(0xb764f000, 4096, PROT_NONE)   = 0
mmap2(0xb7650000, 12288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a8000) = 0xb7650000
mmap2(0xb7653000, 10876, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7653000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb74a6000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0xb74a5000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb74a5700, limit:1048575,
seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
mprotect(0xb7650000, 8192, PROT_READ)   = 0
mprotect(0xb76d3000, 4096, PROT_READ)   = 0
mprotect(0x8049000, 4096, PROT_READ)    = 0
mprotect(0xb7717000, 4096, PROT_READ)   = 0
munmap(0xb76db000, 87672)               = 0
brk(0)                                  = 0x895c000
brk(0x897d000)                          = 0x897d000
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x80485d2} ---
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)

+) The ‘configure’ options you used when building GMP:
sudo apt-get install m4
./configure
make
sudo make install
make check

+) gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.8/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.8.4-2ubuntu1~14.04.3'
--with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-i386
--with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror
--with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu
--target=i686-linux-gnu
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)

+) uname -a:
Linux ubuntu 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22 15:32:27
UTC 2016 i686 i686 i686 GNU/Linux

+) ./config.guess:
haswell-pc-linux-gnu

+) ./configfsf.guess
i686-pc-linux-gnu

The finally, I can use "mpz_init(x);mpz_init(y);" instead of
"mpz_inits(x,y)" to get correct!

Thank you,

Nguyen Van Thong


More information about the gmp-bugs mailing list