Bug#284978: general: libgmp segfaults on generating 48402688-bit random number
Thomas Womack <twomack@chiark.greenend.org.uk> writes:
> Package: general
> Version: 20041209
> Severity: normal
>
> The program
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
> #include "gmp.h"
Do you have libgmp2-dev or libgmp3-dev installed?
> int main(int argc, char** argv)
> {
> mpz_t A,B,C;
> gmp_randstate_t state;
>
> gmp_randinit_default(state);
> gmp_randseed_ui(state, 3);
>
> mpz_urandomb(A, state, 48402688);
> mpz_urandomb(B, state, 845*32);
> mpz_gcd(C,A,B);
> }
>
> compiled with gcc = gcc-2.95.4, gmp = gmp-4.0.1
With gcc-3.3 and libgmp3-dev_4.1.4-5_amd64.deb
mrvn@frosties:~% gcc -g -O2 -W -Wall -o foo foo.c -lgmp
foo.c: In function `main':
foo.c:6: warning: unused parameter `argc'
foo.c:6: warning: unused parameter `argv'
mrvn@frosties:~% ./foo
zsh: segmentation fault ./foo
Program received signal SIGSEGV, Segmentation fault.
0x0000002a95673f00 in __gmp_rand () from /usr/lib/libgmp.so.3
(gdb) bt
#0 0x0000002a95673f00 in __gmp_rand () from /usr/lib/libgmp.so.3
#1 0x0000002a95673eba in __gmp_rand () from /usr/lib/libgmp.so.3
#2 0x0000002a95687164 in __gmpz_urandomb () from /usr/lib/libgmp.so.3
#3 0x0000000000400782 in main (argc=4196299, argv=0x9e) at foo.c:14
Same with gcc-3.4.
> segfaults in the mpz_urandomb() function
> with a back-trace
> #0 0x4003d051 in __gmpn_copyi () from /usr/lib/libgmp.so.3
> #1 0x40023012 in __gmp_randinit_lc_2exp () from /usr/lib/libgmp.so.3
> #2 0x4002310d in __gmp_rand () from /usr/lib/libgmp.so.3
> #3 0x400331f8 in __gmpz_urandomb () from /usr/lib/libgmp.so.3
> #4 0x0804861b in main (argc=1, argv=0xbffffca4) at use-gcds-BUG.c:14
>
> -- System Information
> Debian Release: 3.0
> Kernel Version: Linux chiark 2.4.28 #2 SMP Mon Nov 22 15:56:31 GMT 2004 i686 unknown
Kernel Version: Linux frosties 2.6.8-frosties-1 #2 Sun Oct 3 22:06:03 CEST 2004 x86_64 GNU/Linux
MfG
Goswin
Reply to: