Mar 5, 2014

How to resolve longjmp issue of CURL in Ubuntu 12.04 (or others)

1. There is a bug related to libcurl
*** longjmp causes uninitialized stack frame ***: /home/user/myexe terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f8d8911c7f7]
/lib/x86_64-linux-gnu/libc.so.6(+0xf8789)[0x7f8d8911c789]
/lib/x86_64-linux-gnu/libc.so.6(__longjmp_chk+0x33)[0x7f8d8911c6f3]
/usr/lib/x86_64-linux-gnu/libcurl-nss.so.4(+0xd795)[0x7f8d88272795]
/lib/x86_64-linux-gnu/libc.so.6(+0x36420)[0x7f8d8905a420]
/lib/x86_64-linux-gnu/libc.so.6(__poll+0x53)[0x7f8d890f9773]
/usr/lib/libdbus-c++-1.so.0(_ZN4DBus15DefaultMainLoop8dispatchEv+0x161)[0x7f8d89b6b481]
/usr/lib/libdbus-c++-1.so.0(_ZN4DBus13BusDispatcher5enterEv+0x63)[0x7f8d89b6c293]

2. Check the executable file with ldd
ldd /home/user/myexe | grep curl
        libcurl-nss.so.4 => /usr/lib/x86_64-linux-gnu/libcurl-nss.so.4 (0x00007fce983f2000)
"/usr/lib/x86_64-linux-gnu/libcurl-nss.so.4" is where the location  of libcurl with the bug is.

3. Go to http://curl.haxx.se/download.html and download src of libcurl.

4. Follow the instruction http://curl.haxx.se/dev/readme-ares.html to build c-ares and libcurl
The compiled library would be placed in "/usr/local/lib" .

5. Add the compiling argument in gcc command to specify the library location:
gcc -lcurl -o fuse -L /usr/local/lib -Wl,-rpath /usr/local/lib

6. Test the result~

Reference:
[1] http://stackoverflow.com/questions/8835108/specify-non-default-shared-library-path-in-gcc-linux
[2] http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame
[3] http://curl.haxx.se/download.html
[4] http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading
[5] http://curl.haxx.se/mail/lib-2008-06/0329.html