cURL / Mailing Lists / curl-library / Single Mail

curl-library

Issues in using 64 bit curl library on a RHEL 64 bit machine

From: Chitra Nanda <chitrananda9_at_gmail.com>
Date: Mon, 14 Jun 2010 15:09:45 +0530

Hi,

I am using the curl library for downloading a file. I am running into some
issue with the usage of curl library on 64 bit machines( on RHEL 5.3 - 64
bit machine). It works fine on a 32 bit machine(RHEL 32 bit machine) . I am
trying the same piece of code on both 32 bit and 64 bit machine. I can see
it throws up segmentation fault on a 64 bit machine.

If I try to link the library dynamically at compile time then I don't run
into any issues. But if I try to link it at runtime I run into issues. I am
trying to load the curl library dynamically at runtime and trying to
download a file from a remote machine using C++ on Linux(RHEL 5.3 - 64 bit
machine).

I am pasting the piece of code which is causing the issue over here. If you
need more info please let me know about the same.

Any help in this regard is highly appreciated. Thanks for your time.

====================================================================

#include <stdio.h>
#include <dlfcn.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>

int main()
{

    CURLcode res;

    void* sdl_library = dlopen( "/lib64/libcurl.so.4", RTLD_GLOBAL |
RTLD_NOW );

    if ( sdl_library == 0 )
    {
        printf("Checking with the /usr/lib location for libcurl\n");
        sdl_library = dlopen( "/usr/lib64/libcurl.so.4", RTLD_GLOBAL |
RTLD_NOW );
        if ( sdl_library == 0 )
        {
            printf("Checking with the /usr/lib without version location for
libcurl \n");
             sdl_library = dlopen( "/usr/lib64/libcurl.so", RTLD_GLOBAL |
RTLD_NOW );
        }
    }

    if ( sdl_library != 0 )
    {
      FILE *fp;
      char *errstr;
      const char * pch = strrchr( "/tmp/test.txt", '/' );
      if ( pch )
      {
         filename = pch + 1;
         fp = fopen( "test.txt", "wb" );
         if ( fp )
         {
           CURL *curl;
           CURL* ( *fptr )();
           *( void ** )( &fptr ) = dlsym( sdl_library, "curl_easy_init" );
           if ( fptr == 0 )
           {
              printf("unable to locate function curl_easy_init in curl so
\n" );
              return -1;
           }
           else
           {
               curl = ( *fptr )();
               if ( curl )
               {
                 CURLcode ( *fptr1 ) ( CURL*, int, char* );
                 *( void ** )( &fptr1 ) = dlsym( sdl_library,
"curl_easy_setopt" );
                 if ( fptr1 == 0 )
                 {
                    printf("unable to locate function curl_easy_setopt in
curl so \n");
                    return -1;
                 }
                 else
                 {
                   //Sample URL just for testing, whatever is the URL it
fails on a 64 bit machine
                   res = ( *fptr1 ) ( curl, CURLOPT_URL, const_cast<char*>(
"http://10.12.13.14//test.txt" ) );
                   if(res != 0)
                     printf("Error accessing curl url %d \n", res);

//////////////////////////////////////////////////////////////
                    CURLcode ( *fptr3 ) ( CURL*, int, FILE* );
                    *( void ** )( &fptr3 ) = dlsym( sdl_library,
"curl_easy_setopt" );
                    //CURL_ERR_CHECK( errstr );
                    if ( fptr3 == 0 )
                    {
                        printf("unable to locate function curl_easy_setopt
in curl so \n" );
                        return -1;
                    }
                    else
                    {
                       res = ( *fptr3 ) ( curl, CURLOPT_FILE, fp );
                       if(res != 0)
                           printf("Error accessing curl url %d \n", res);

////////////////////////////////////////////////////////////
                       CURLcode ( *fptr5 ) ( CURL*, int, char* );
                       *( void ** )( &fptr5 ) = dlsym( sdl_library,
"curl_easy_setopt" );
                       //CURL_ERR_CHECK( errstr );
                       if ( fptr5 == 0 )
                       {
                           printf("unable to locate function
curl_easy_setopt in curl so \n" );
                           return -1;
                       }
                       else
                       {
                           char curlerr[512];
                           res = ( *fptr5 ) ( curl, CURLOPT_ERRORBUFFER,
curlerr );
                           if(res != 0)
                           {
                              printf("Error accessing curl url %d \n", res);
                              //printf("Error string %s \n",
curl_easy_strerror(res));
                           }

/////////////////////////////////////////////////////////////
                           CURLcode ( *fptr2 )( CURL* );
                           *( void ** )( &fptr2 ) = dlsym( sdl_library,
"curl_easy_perform" );
                           if ( fptr2 == 0 )
                           {
                              printf("unable to locate function
curl_easy_perform in curl so \n" );
                              return -1;
                           }
                       }//End of fptr5
                    }//End of fptr3
               }//End of Ptr1
           }//End of Curl
        fclose( fp );
    }//End of fptr
     }//End of fp
   } //End of pch
  } //End of sld_library
}//End of Main

====================================================================

# gdb a.out
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...
(gdb) run
Starting program: /root/a.out
Checking with the /usr/lib location for libcurl
Checking with the /usr/lib without version location for libcurl

Program received signal SIGSEGV, Segmentation fault.
0x000000393ac283cd in curl_easy_perform () from /usr/lib64/libcurl.so
(gdb) bt
#0 0x000000393ac283cd in curl_easy_perform () from /usr/lib64/libcurl.so
#1 0x0000002200000000 in ?? ()
#2 0x0000000000000000 in ?? ()
(gdb)

----------------------------------------------------------------------------------------------------------------------------------------

Regards,
Chitra

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-06-14