Skip to content

Commit

Permalink
Merge branch 'lurcher:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chipitsine authored Oct 25, 2024
2 parents 1815905 + e72afd6 commit c100697
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 17 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* Added some missing error logging in SQLSpecialColumns[W]
* Set driver_name in SQLBrowseConnect(W) to "" to prevent seg fault if lib not found
* Various mem buffers fixes. Thanks chipitsine
* Fix race condition with threaded applications where SQLGetPrivateProfileString can fail
due to collision with loading driver library during connection

8-Aug-2023
2.3.12
Expand Down
2 changes: 2 additions & 0 deletions DriverManager/SQLDriverConnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ struct con_pair * con_p;
if ( keyword )
{
con_p = malloc( sizeof( *con_p ));
if ( !con_p )
return NULL;
con_p -> keyword = keyword;
con_p -> attribute = value;
return con_p;
Expand Down
39 changes: 29 additions & 10 deletions DriverManager/__connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,23 @@ char *__find_lib_name( char *dsn, char *lib_name, char *driver_name )
{
char driver[ INI_MAX_PROPERTY_VALUE + 1 ];
char driver_lib[ INI_MAX_PROPERTY_VALUE + 1 ];
int mode;

SQLSetConfigMode( ODBC_USER_DSN );
/*
* this cound mess up threaded programs by changing the mode
*/

__lock_config_mode();

mode = __get_config_mode();

__set_config_mode( ODBC_USER_DSN );

/*
* GET DRIVER FROM ODBC.INI
*/

SQLGetPrivateProfileString( dsn, "Driver", "",
__SQLGetPrivateProfileStringNL( dsn, "Driver", "",
driver_lib, sizeof( driver_lib ), "ODBC.INI" );

if ( driver_lib[ 0 ] == 0 )
Expand All @@ -130,14 +139,18 @@ char *__find_lib_name( char *dsn, char *lib_name, char *driver_name )
* if not found look in system DSN
*/

SQLSetConfigMode( ODBC_SYSTEM_DSN );
__set_config_mode( ODBC_SYSTEM_DSN );

SQLGetPrivateProfileString( dsn, "Driver", "",
__SQLGetPrivateProfileStringNL( dsn, "Driver", "",
driver_lib, sizeof( driver_lib ), "ODBC.INI" );

SQLSetConfigMode( ODBC_BOTH_DSN );
if ( driver_lib[ 0 ] == 0 )
if ( driver_lib[ 0 ] == 0 ) {
__set_config_mode( mode );
__unlock_config_mode();
return NULL;
}

__set_config_mode( ODBC_BOTH_DSN );
}

/*
Expand All @@ -151,32 +164,38 @@ char *__find_lib_name( char *dsn, char *lib_name, char *driver_name )
strcpy( driver, driver_lib );

/*
* allow the use of "User odbcinst files
* allow the use of User odbcinst files, use no lock version as its
* protected by mutex
*/

#ifdef PLATFORM64
SQLGetPrivateProfileString( driver, "Driver64", "",
__SQLGetPrivateProfileStringNL( driver, "Driver64", "",
driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );

if ( driver_lib[ 0 ] == '\0' )
{
SQLGetPrivateProfileString( driver, "Driver", "",
__SQLGetPrivateProfileStringNL( driver, "Driver", "",
driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );
}
#else
SQLGetPrivateProfileString( driver, "Driver", "",
__SQLGetPrivateProfileStringNL( driver, "Driver", "",
driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );
#endif

strcpy( driver_name, driver );

if ( driver_lib[ 0 ] == 0 ) {
__set_config_mode( mode );
__unlock_config_mode();
return NULL;
}
}

strcpy( lib_name, driver_lib );

__set_config_mode( mode );
__unlock_config_mode();

return lib_name;
}

Expand Down
8 changes: 8 additions & 0 deletions cur/SQLExecDirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,23 @@ SQLRETURN get_column_names( CLHSTMT cl_statement )

cl_statement -> column_names = malloc( sizeof(char *)
* cl_statement -> column_count );
if ( !cl_statement->column_names )
return SQL_ERROR;

cl_statement -> data_type = malloc( sizeof( SQLSMALLINT )
* cl_statement -> column_count );
if ( !cl_statement->data_type )
return SQL_ERROR;

cl_statement -> column_size = malloc( sizeof( SQLULEN )
* cl_statement -> column_count );
if ( !cl_statement->column_size )
return SQL_ERROR;

cl_statement -> decimal_digits = malloc( sizeof( SQLSMALLINT )
* cl_statement -> column_count );
if ( !cl_statement->decimal_digits )
return SQL_ERROR;

for ( i = 1; i <= cl_statement -> column_count; i ++ )
{
Expand Down
9 changes: 9 additions & 0 deletions include/odbcinstext.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ BOOL _SQLDriverConnectPromptW(

void __set_config_mode( int mode );
int __get_config_mode( void );
void __lock_config_mode( void );
void __unlock_config_mode( void );

int inst_logPushMsg(
char *pszModule,
Expand All @@ -220,6 +222,13 @@ int inst_logPushMsg(
int inst_logPeekMsg( long nMsg, HLOGMSG *phMsg );
int inst_logClear();

int __SQLGetPrivateProfileStringNL( LPCSTR pszSection,
LPCSTR pszEntry,
LPCSTR pszDefault,
LPSTR pRetBuffer,
int nRetBuffer,
LPCSTR pszFileName
);

/*
* we should look at caching this info, the calls can become expensive
Expand Down
2 changes: 1 addition & 1 deletion include/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


/****************************
* default to 3.51 declare something else before here and you get a whole new ball of wax
* default to 3.8 declare something else before here and you get a whole new ball of wax
***************************/
#ifndef ODBCVER
#define ODBCVER 0x0380
Expand Down
2 changes: 2 additions & 0 deletions ini/iniObjectInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ int iniObjectInsert( HINI hIni, char *pszObject )

/* CREATE OBJECT STRUCT */
hObject = malloc( sizeof(INIOBJECT) );
if ( !hObject )
return INI_ERROR;
hIni->hCurProperty = NULL;
hObject->hFirstProperty = NULL;
hObject->hLastProperty = NULL;
Expand Down
4 changes: 4 additions & 0 deletions ini/iniOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c

/* INIT STATEMENT */
*hIni = malloc( sizeof(INI) );
if ( !*hIni )
return INI_ERROR;
if ( pszFileName && pszFileName != STDINFILE )
strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX );
else if ( pszFileName == STDINFILE )
Expand Down Expand Up @@ -363,6 +365,8 @@ int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, c

/* INIT STATEMENT */
*hIni = malloc( sizeof(INI) );
if ( !*hIni )
return INI_ERROR;
if ( pszFileName && pszFileName != STDINFILE )
strncpy((*hIni)->szFileName, pszFileName, ODBC_FILENAME_MAX );
else if ( pszFileName == STDINFILE )
Expand Down
2 changes: 2 additions & 0 deletions log/logOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int logOpen( HLOG *phLog, char *pszProgramName, char *pszLogFile, long nMaxMsgs

/* LOG STRUCT */
*phLog = malloc( sizeof(LOG) );
if ( !*phLog )
return LOG_ERROR;
(*phLog)->nMaxMsgs = nMaxMsgs;
(*phLog)->hMessages = lstOpen();
(*phLog)->bOn = 0;
Expand Down
16 changes: 13 additions & 3 deletions odbcinst/SQLConfigDataSource.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static BOOL SQLConfigDataSourceWide( HWND hWnd,
char szDriverSetup[INI_MAX_PROPERTY_VALUE+1];
char szIniName[ ODBC_FILENAME_MAX * 2 + 3 ];
char b1[ ODBC_FILENAME_MAX + 1 ], b2[ ODBC_FILENAME_MAX + 1 ];
int config_mode;

/* SANITY CHECKS */
if ( pszDriver == NULL || pszAttributes == NULL )
Expand Down Expand Up @@ -69,6 +70,9 @@ static BOOL SQLConfigDataSourceWide( HWND hWnd,
sprintf( szIniName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ) );
#endif

__lock_config_mode();
config_mode = __get_config_mode();

/* OK */
#ifdef __OS2__
if ( iniOpen( &hIni, szIniName, "#;", '[', ']', '=', TRUE, 1L ) != INI_SUCCESS )
Expand All @@ -77,6 +81,8 @@ static BOOL SQLConfigDataSourceWide( HWND hWnd,
#endif
{
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
__set_config_mode( config_mode );
__unlock_config_mode();
return FALSE;
}

Expand Down Expand Up @@ -105,7 +111,8 @@ static BOOL SQLConfigDataSourceWide( HWND hWnd,
char szError[ 512 ];
sprintf( szError, "Could not find Setup property for (%.400s) in system information", pszDriver );
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, szError );
__set_config_mode( ODBC_BOTH_DSN );
__set_config_mode( config_mode );
__unlock_config_mode();
return FALSE;
}

Expand Down Expand Up @@ -184,15 +191,18 @@ static BOOL SQLConfigDataSourceWide( HWND hWnd,
else
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );

__set_config_mode( ODBC_BOTH_DSN );
__set_config_mode( config_mode );
__unlock_config_mode();

return nReturn;

}

inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
iniClose( hIni );

__set_config_mode( ODBC_BOTH_DSN );
__set_config_mode( config_mode );
__unlock_config_mode();

return FALSE;
}
Expand Down
10 changes: 10 additions & 0 deletions odbcinst/SQLCreateDataSource.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ char* _multi_string_alloc_and_copy( LPCWSTR in )
}

chr = malloc( len + 2 );
if ( !chr )
return NULL;

len = 0;
while ( in[ len ] != 0 || in[ len + 1 ] != 0 )
Expand Down Expand Up @@ -80,6 +82,8 @@ char* _single_string_alloc_and_copy( LPCWSTR in )
}

chr = malloc( ulen + 1 );
if ( !chr )
return NULL;

len = 0;
ulen = 0;
Expand Down Expand Up @@ -127,6 +131,8 @@ char* _single_string_alloc_and_copy( LPCWSTR in )
}

chr = malloc( len + 1 );
if ( !chr )
return NULL;

len = 0;
while ( in[ len ] != 0 )
Expand Down Expand Up @@ -157,6 +163,8 @@ SQLWCHAR* _multi_string_alloc_and_expand( LPCSTR in )
}

chr = malloc(sizeof( SQLWCHAR ) * ( len + 2 ));
if ( !chr )
return NULL;

len = 0;
while ( in[ len ] != 0 || in[ len + 1 ] != 0 )
Expand Down Expand Up @@ -186,6 +194,8 @@ SQLWCHAR* _single_string_alloc_and_expand( LPCSTR in )
}

chr = malloc( sizeof( SQLWCHAR ) * ( len + 1 ));
if ( !chr )
return NULL;

len = 0;
while ( in[ len ] != 0 )
Expand Down
2 changes: 2 additions & 0 deletions odbcinst/SQLGetConfigMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ BOOL SQLGetConfigMode( UWORD *pnConfigMode )
{
inst_logClear();

__lock_config_mode();
*pnConfigMode = __get_config_mode();
__unlock_config_mode();

return TRUE;
}
Expand Down
19 changes: 18 additions & 1 deletion odbcinst/SQLGetPrivateProfileString.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void __clear_ini_cache( void )

#endif

int SQLGetPrivateProfileString( LPCSTR pszSection,
int __SQLGetPrivateProfileStringNL( LPCSTR pszSection,
LPCSTR pszEntry,
LPCSTR pszDefault,
LPSTR pRetBuffer,
Expand Down Expand Up @@ -605,6 +605,23 @@ int SQLGetPrivateProfileString( LPCSTR pszSection,
return ret;
}

int SQLGetPrivateProfileString( LPCSTR pszSection,
LPCSTR pszEntry,
LPCSTR pszDefault,
LPSTR pRetBuffer,
int nRetBuffer,
LPCSTR pszFileName
)
{
int ret;

__lock_config_mode();
ret = __SQLGetPrivateProfileStringNL( pszSection, pszEntry, pszDefault, pRetBuffer, nRetBuffer, pszFileName );
__unlock_config_mode();

return ret;
}

int INSTAPI SQLGetPrivateProfileStringW( LPCWSTR lpszSection,
LPCWSTR lpszEntry,
LPCWSTR lpszDefault,
Expand Down
Loading

0 comments on commit c100697

Please sign in to comment.