[unixODBC-dev] lt_dlerror may cause potential issue in multi-thread environment

xiaonan xn212516 at 163.com
Fri Apr 12 02:40:09 BST 2013


 Hi, Nick:

    Because lt_dlerror() function is not thread-safe, in the following code:
    
    if ( !(connection -> dl_handle = odbc_dlopen( driver_lib )))
    {
        char txt[ 2048 ];

        sprintf( txt, "Can't open lib '%s' : %s",
                driver_lib, lt_dlerror());

        ......
        
        return 0;
    }
    
    In multi-thread environment, the lt_dlerror() may return other thread's error, or even NULL.
    
    In your latest modification:
    
    if ( !(connection -> dl_handle = odbc_dlopen( driver_lib )))
    {
        char txt[ 2048 ];
        const char *err;

        err = lt_dlerror();

        sprintf( txt, "Can't open lib '%s' : %s",
                driver_lib, err ? err : "NULL ERROR RETURN" );

        ......
        return 0;
    }
    
    This issue still exits.
    
    Personally, I think the function of odbc_dlopen() can be modified as this:
    
    static void *odbc_dlopen( char *libname, char *err );
    {
        ......
        hand = lt_dlopen( libname );
        if (hand)
        {
        }
        else
        {
            sprintf(err, "%s", lt_dlerror());
        }
    }
    
    So if there is a error, the error can be returned correctly:
    
    char txt[ 2048 ];
    char err[2048]
    if ( !(connection -> dl_handle = odbc_dlopen( driver_lib, err)))
    {
        
        sprintf( txt, "Can't open lib '%s' : %s",
                driver_lib, err);

        ......
        
        return 0;
    }
    
    Could you help to check it? Thanks very much!
    
Best Regards
Nan Xiao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20130412/05f130df/attachment.html>


More information about the unixODBC-dev mailing list