Skip to content

Commit

Permalink
bug fix when SQLGetPrivateProfileString() is called to get a list of …
Browse files Browse the repository at this point in the history
…sections or a list of keys
  • Loading branch information
lurcher committed Jul 5, 2018
1 parent 3fe289d commit 4209bc2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Craig A Berry
Dave Berry
David Brown
Dmitriy Yusupov
Donnie Pinkston
Emile Heitor
Erik Lundqvist
Frediano Ziglio
Expand Down Expand Up @@ -80,7 +81,7 @@ Martin Kittel
Martin Lacko
Max Khon
Michael Koch
Michael Vetter
Michael Vetter
Miloslav Marik
Mike Schultz
Mikko Vierula
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add --with-stats-ftok-name configure option to allow the selection of a file name
used to generate the IPC id when collecting stats. Default is the system odbc.ini file
* Improve diag record handling with the behavior of Windows DM and export SQLCancelHandle
* bug fix when SQLGetPrivateProfileString() is called to get a list of sections or a list of keys

19-March-2018
2.3.6
Expand Down
1 change: 1 addition & 0 deletions include/odbcinstext.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ void _single_copy_to_wide( SQLWCHAR *out, LPCSTR in, int len );
SQLWCHAR* _multi_string_alloc_and_expand( LPCSTR in );
SQLWCHAR* _single_string_alloc_and_expand( LPCSTR in );
void _single_copy_from_wide( SQLCHAR *out, LPCWSTR in, int len );
int _multi_string_length( LPCSTR in );

/*
* To support finding UI plugin
Expand Down
16 changes: 16 additions & 0 deletions odbcinst/SQLCreateDataSource.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ void _multi_string_copy_to_wide( SQLWCHAR *out, LPCSTR in, int len )
*out++ = 0;
}

int _multi_string_length( LPCSTR in )
{
LPCSTR ch;

if ( !in )
return 0;

for ( ch = in ; !(*ch == 0 && *(ch + 1) == 0) ; ch ++ );

/* The convention seems to be to exclude the very last '\0' character from
* the count, so that is what we do here.
*/
return ch - in + 1;
}


/*!
* \brief Invokes a UI (a wizard) to walk User through creating a DSN.
*
Expand Down
28 changes: 20 additions & 8 deletions odbcinst/SQLGetPrivateProfileString.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,22 @@ int SQLGetPrivateProfileString( LPCSTR pszSection,
if ( pszSection == NULL )
{
_odbcinst_GetSections( hIni, pRetBuffer, nRetBuffer, &nBufPos );

if (nBufPos > 0)
ret = _multi_string_length(pRetBuffer);
else
ret = 0; /* Indicate not found */
}
/*****************************************************
* EXTRACT ENTRIES
*****************************************************/
else if ( pszEntry == NULL )
{
_odbcinst_GetEntries( hIni, pszSection, pRetBuffer, nRetBuffer, &nBufPos );
if (nBufPos > 0)
ret = _multi_string_length(pRetBuffer);
else
ret = 0; /* Indicate not found */
}
/*****************************************************
* EXTRACT AN ENTRY
Expand Down Expand Up @@ -577,19 +586,19 @@ int SQLGetPrivateProfileString( LPCSTR pszSection,
else
{
iniValue( hIni, szValue );
if ( pRetBuffer )
{
strncpy( pRetBuffer, szValue, nRetBuffer );
pRetBuffer[ nRetBuffer - 1 ] = '\0';
}
if ( pRetBuffer )
{
strncpy( pRetBuffer, szValue, nRetBuffer );
pRetBuffer[ nRetBuffer - 1 ] = '\0';
}
nBufPos = strlen( szValue );
}

ret = strlen( pRetBuffer );
}

iniClose( hIni );

ret = strlen( pRetBuffer );

save_ini_cache( ret, pszSection, pszEntry, pszDefault, pRetBuffer, nRetBuffer, pszFileName );

return ret;
Expand Down Expand Up @@ -647,7 +656,10 @@ int INSTAPI SQLGetPrivateProfileStringW( LPCWSTR lpszSection,
{
if ( buf && lpszRetBuffer )
{
_single_copy_to_wide( lpszRetBuffer, buf, ret + 1 );
if ( !lpszSection || !lpszEntry )
_multi_string_copy_to_wide( lpszRetBuffer, buf, ret );
else
_single_copy_to_wide( lpszRetBuffer, buf, ret );
}
}

Expand Down

0 comments on commit 4209bc2

Please sign in to comment.