From e66e43e8945854091d534e25d599da5ef3389552 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 20 Nov 2010 20:31:45 +0000 Subject: [PATCH] 2010-11-20 21:31 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rdd/dbfntx/dbfntx1.c * harbour/src/rdd/dbfnsx/dbfnsx1.c * harbour/src/rdd/dbfcdx/dbfcdx1.c * harbour/contrib/rddads/ads1.c * casting cleanup * harbour/contrib/hbssl/ssl.c * use hb_itemGetWriteCL() instead of hb_itemUnShareString() ! do not allow to overwrite trailing 0 in string item - we have such code in FREAD() which uses hb_parcsize() instead of hb_parclen() but only for strict compatibility with CL5.x FREAD() function and it should not be replicated in any other code - strings without trailing 0 may cause GPF in some other code uisng [hb_]str*() C functions. --- harbour/ChangeLog | 16 ++++++++++ harbour/contrib/hbssl/ssl.c | 52 ++++++++++++++++---------------- harbour/contrib/rddads/ads1.c | 15 ++++----- harbour/src/rdd/dbfcdx/dbfcdx1.c | 6 ++-- harbour/src/rdd/dbfnsx/dbfnsx1.c | 6 ++-- harbour/src/rdd/dbfntx/dbfntx1.c | 12 ++++---- 6 files changed, 62 insertions(+), 45 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f544414e21..f341cc17ae 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,22 @@ The license applies to all entries newer than 2009-04-28. */ +2010-11-20 21:31 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/rdd/dbfntx/dbfntx1.c + * harbour/src/rdd/dbfnsx/dbfnsx1.c + * harbour/src/rdd/dbfcdx/dbfcdx1.c + * harbour/contrib/rddads/ads1.c + * casting cleanup + + * harbour/contrib/hbssl/ssl.c + * use hb_itemGetWriteCL() instead of hb_itemUnShareString() + ! do not allow to overwrite trailing 0 in string item - we + have such code in FREAD() which uses hb_parcsize() instead + of hb_parclen() but only for strict compatibility with CL5.x + FREAD() function and it should not be replicated in any other + code - strings without trailing 0 may cause GPF in some other + code uisng [hb_]str*() C functions. + 2010-11-20 19:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbgd/tests/tpoly.prg * Applied patch from Tamas. Nicer flakes! diff --git a/harbour/contrib/hbssl/ssl.c b/harbour/contrib/hbssl/ssl.c index 95097592e2..947f322481 100644 --- a/harbour/contrib/hbssl/ssl.c +++ b/harbour/contrib/hbssl/ssl.c @@ -466,24 +466,24 @@ HB_FUNC( SSL_READ ) if( ssl ) { - PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING ); - int nRead; + PHB_ITEM pItem = hb_param( 2, HB_IT_STRING ); + char * pBuffer; + HB_SIZE nLen; + int nRead = 0; - if( pBuffer && HB_ISBYREF( 2 ) ) + if( pItem && HB_ISBYREF( 2 ) && + hb_itemGetWriteCL( pItem, &pBuffer, &nLen ) ) { - nRead = HB_ISNUM( 3 ) ? hb_parni( 3 ) : ( int ) hb_parclen( 2 ); - - if( ( HB_SIZE ) nRead <= hb_parcsiz( 2 ) ) + if( HB_ISNUM( 3 ) ) { - pBuffer = hb_itemUnShareString( pBuffer ); - - nRead = SSL_read( ssl, ( void * ) hb_itemGetCPtr( pBuffer ), nRead ); + nRead = hb_parni( 3 ); + if( nRead >= 0 && nRead < ( int ) nLen ) + nLen = nRead; } - else - nRead = 0; + nRead = nLen >= INT_MAX ? INT_MAX : ( int ) nLen; + + nRead = SSL_read( ssl, pBuffer, nRead ); } - else - nRead = 0; hb_retni( nRead ); } @@ -500,24 +500,24 @@ HB_FUNC( SSL_PEEK ) if( ssl ) { - PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING ); - int nRead; + PHB_ITEM pItem = hb_param( 2, HB_IT_STRING ); + char * pBuffer; + HB_SIZE nLen; + int nRead = 0; - if( pBuffer && HB_ISBYREF( 2 ) ) + if( pItem && HB_ISBYREF( 2 ) && + hb_itemGetWriteCL( pItem, &pBuffer, &nLen ) ) { - nRead = HB_ISNUM( 3 ) ? hb_parni( 3 ) : ( int ) hb_parclen( 2 ); - - if( ( HB_SIZE ) nRead <= hb_parcsiz( 2 ) ) + if( HB_ISNUM( 3 ) ) { - pBuffer = hb_itemUnShareString( pBuffer ); - - nRead = SSL_peek( ssl, ( void * ) hb_itemGetCPtr( pBuffer ), nRead ); + nRead = hb_parni( 3 ); + if( nRead >= 0 && nRead < ( int ) nLen ) + nLen = nRead; } - else - nRead = 0; + nRead = nLen >= INT_MAX ? INT_MAX : ( int ) nLen; + + nRead = SSL_peek( ssl, pBuffer, nRead ); } - else - nRead = 0; hb_retni( nRead ); } diff --git a/harbour/contrib/rddads/ads1.c b/harbour/contrib/rddads/ads1.c index cc782513ab..ec54013190 100644 --- a/harbour/contrib/rddads/ads1.c +++ b/harbour/contrib/rddads/ads1.c @@ -2925,7 +2925,7 @@ static HB_ERRCODE adsCreate( ADSAREAP pArea, LPDBOPENINFO pCreateInfo ) hConnection = HB_ADS_DEFCONNECTION( pCreateInfo->ulConnection ); - pArea->szDataFileName = hb_strdup( ( char * ) pCreateInfo->abName ); + pArea->szDataFileName = hb_strdup( pCreateInfo->abName ); fUnicode = HB_FALSE; pArea->maxFieldLen = 0; @@ -3363,7 +3363,8 @@ static HB_ERRCODE adsOpen( ADSAREAP pArea, LPDBOPENINFO pOpenInfo ) /* See adsGettValue() for why we don't use pArea->area.uiMaxFieldNameLength here */ UNSIGNED16 usBufLen, usType, usDecimals; DBFIELDINFO dbFieldInfo; - char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ], * szFile; + char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ]; + const char * szFile; HB_BOOL fDictionary = HB_FALSE, fUnicode = HB_FALSE; HB_TRACE(HB_TR_DEBUG, ("adsOpen(%p)", pArea)); @@ -3381,7 +3382,7 @@ static HB_ERRCODE adsOpen( ADSAREAP pArea, LPDBOPENINFO pOpenInfo ) #endif #endif } - szFile = ( char * ) pOpenInfo->abName; + szFile = pOpenInfo->abName; if( pArea->hTable != 0 ) { @@ -3423,7 +3424,7 @@ static HB_ERRCODE adsOpen( ADSAREAP pArea, LPDBOPENINFO pOpenInfo ) } else { - commonError( pArea, EG_OPEN, ( HB_ERRCODE ) u32RetVal, 0, ( char * ) pOpenInfo->abName, 0, NULL ); + commonError( pArea, EG_OPEN, ( HB_ERRCODE ) u32RetVal, 0, pOpenInfo->abName, 0, NULL ); return HB_FAILURE; } } @@ -3452,7 +3453,7 @@ static HB_ERRCODE adsOpen( ADSAREAP pArea, LPDBOPENINFO pOpenInfo ) /* 1001 and 7008 are standard ADS Open Errors that will usually be sharing issues */ HB_ERRCODE errOsCode = u32RetVal == 1001 || u32RetVal == 7008 ? 32 : 0; fRetry = commonError( pArea, EG_OPEN, ( HB_ERRCODE ) u32RetVal, errOsCode, - ( const char * ) pOpenInfo->abName, + pOpenInfo->abName, EF_CANRETRY | EF_CANDEFAULT, &pError ) == E_RETRY; } else @@ -3477,7 +3478,7 @@ static HB_ERRCODE adsOpen( ADSAREAP pArea, LPDBOPENINFO pOpenInfo ) pOpenInfo->atomAlias = ""; } - pArea->szDataFileName = hb_strdup( ( char * ) ( pOpenInfo->abName ) ); + pArea->szDataFileName = hb_strdup( pOpenInfo->abName ); pArea->hTable = hTable; pArea->hStatement = hStatement; pArea->hOrdCurrent = 0; @@ -4131,7 +4132,7 @@ static HB_ERRCODE adsOrderCreate( ADSAREAP pArea, LPDBORDERCREATEINFO pOrderInfo if( u32RetVal != AE_SUCCESS ) { - commonError( pArea, EG_CREATE, ( HB_ERRCODE ) u32RetVal, 0, ( char * ) pOrderInfo->abBagName, 0, NULL ); + commonError( pArea, EG_CREATE, ( HB_ERRCODE ) u32RetVal, 0, pOrderInfo->abBagName, 0, NULL ); return HB_FAILURE; } else diff --git a/harbour/src/rdd/dbfcdx/dbfcdx1.c b/harbour/src/rdd/dbfcdx/dbfcdx1.c index 7eca3e560f..18e75c638d 100644 --- a/harbour/src/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/src/rdd/dbfcdx/dbfcdx1.c @@ -7434,7 +7434,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI PHB_ITEM pKeyExp, pForExp = NULL, pResult; char szCpndTagName[ CDX_MAXTAGNAMELEN + 1 ], szTagName[ CDX_MAXTAGNAMELEN + 1 ]; char szFileName[ HB_PATH_MAX ], szTempFile[ HB_PATH_MAX ]; - char *szFor = NULL; + const char *szFor = NULL; LPCDXINDEX pIndex; LPCDXTAG pTag; HB_USHORT uiLen; @@ -7450,7 +7450,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI if( hb_strlentrim( hb_itemGetCPtr( pOrderInfo->abExpr ) ) + ( pArea->dbfarea.area.lpdbOrdCondInfo && pArea->dbfarea.area.lpdbOrdCondInfo->abFor ? - hb_strlentrim( ( const char * ) pArea->dbfarea.area.lpdbOrdCondInfo->abFor ) : 0 ) > + hb_strlentrim( pArea->dbfarea.area.lpdbOrdCondInfo->abFor ) : 0 ) > CDX_HEADEREXPLEN - 2 ) { hb_cdxErrorRT( pArea, EG_DATAWIDTH, EDBF_KEYLENGTH, NULL, 0, 0, NULL ); @@ -7546,7 +7546,7 @@ static HB_ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderI fExclusive = pArea->dbfarea.area.lpdbOrdCondInfo->fExclusive; /* Check conditional expression */ - szFor = ( char * ) pArea->dbfarea.area.lpdbOrdCondInfo->abFor; + szFor = pArea->dbfarea.area.lpdbOrdCondInfo->abFor; if( szFor ) { if( SELF_COMPILE( ( AREAP ) pArea, szFor ) == HB_FAILURE ) diff --git a/harbour/src/rdd/dbfnsx/dbfnsx1.c b/harbour/src/rdd/dbfnsx/dbfnsx1.c index 3c4e23916c..8ddec8a255 100644 --- a/harbour/src/rdd/dbfnsx/dbfnsx1.c +++ b/harbour/src/rdd/dbfnsx/dbfnsx1.c @@ -6739,7 +6739,7 @@ static HB_ERRCODE hb_nsxOrderCreate( NSXAREAP pArea, LPDBORDERCREATEINFO pOrderI fTemporary = pArea->dbfarea.area.lpdbOrdCondInfo->fTemporary; fExclusive = pArea->dbfarea.area.lpdbOrdCondInfo->fExclusive; /* Check conditional expression */ - szFor = ( const char * ) pArea->dbfarea.area.lpdbOrdCondInfo->abFor; + szFor = pArea->dbfarea.area.lpdbOrdCondInfo->abFor; if( pArea->dbfarea.area.lpdbOrdCondInfo->itmCobFor ) /* If we have a codeblock for the conditional expression, use it */ pForExp = hb_itemNew( pArea->dbfarea.area.lpdbOrdCondInfo->itmCobFor ); @@ -6797,10 +6797,10 @@ static HB_ERRCODE hb_nsxOrderCreate( NSXAREAP pArea, LPDBORDERCREATEINFO pOrderI * 3. add the Tag to index file */ fNewFile = !pOrderInfo->atomBagName || !pOrderInfo->atomBagName[0]; - hb_nsxCreateFName( pArea, ( const char * ) pOrderInfo->abBagName, + hb_nsxCreateFName( pArea, pOrderInfo->abBagName, &fProd, szFileName, szTagName ); if( !fNewFile ) - hb_strncpyUpperTrim( szTagName, ( const char * ) pOrderInfo->atomBagName, NSX_TAGNAME ); + hb_strncpyUpperTrim( szTagName, pOrderInfo->atomBagName, NSX_TAGNAME ); pIndex = hb_nsxFindBag( pArea, szFileName ); if( pIndex ) diff --git a/harbour/src/rdd/dbfntx/dbfntx1.c b/harbour/src/rdd/dbfntx/dbfntx1.c index 283bebd384..d4abdb10f4 100644 --- a/harbour/src/rdd/dbfntx/dbfntx1.c +++ b/harbour/src/rdd/dbfntx/dbfntx1.c @@ -4616,7 +4616,7 @@ static int hb_ntxQuickSortCompare( LPNTXSORTINFO pSort, HB_BYTE * pKey1, HB_BYTE { int iLen = pSort->keyLen, i; - i = hb_ntxValCompare( pSort->pTag, (char *) pKey1, iLen, (char *) pKey2, iLen, HB_TRUE ); + i = hb_ntxValCompare( pSort->pTag, (const char *) pKey1, iLen, (const char *) pKey2, iLen, HB_TRUE ); if( i == 0 ) { if( pSort->pTag->fSortRec ) @@ -4861,7 +4861,7 @@ static void hb_ntxSortOrderPages( LPNTXSORTINFO pSort ) m = ( l + r ) >> 1; ulPage = pSort->pSortedPages[ m ]; pTmp = &pSort->pSwapPage[ ulPage ].pKeyPool[ pSort->pSwapPage[ ulPage ].ulCurKey * ( iLen + 4 ) ]; - i = hb_ntxValCompare( pSort->pTag, (char *) pKey, iLen, (char *) pTmp, iLen, HB_TRUE ); + i = hb_ntxValCompare( pSort->pTag, (const char *) pKey, iLen, (const char *) pTmp, iLen, HB_TRUE ); if( i == 0 ) { if( pSort->pTag->fSortRec ) @@ -4912,7 +4912,7 @@ static HB_BOOL hb_ntxSortKeyGet( LPNTXSORTINFO pSort, HB_BYTE ** pKeyVal, HB_ULO m = ( l + r ) >> 1; ulPg = pSort->pSortedPages[ m ]; pTmp = &pSort->pSwapPage[ ulPg ].pKeyPool[ pSort->pSwapPage[ ulPg ].ulCurKey * ( iLen + 4 ) ]; - i = hb_ntxValCompare( pSort->pTag, (char *) pKey, iLen, (char *) pTmp, iLen, HB_TRUE ); + i = hb_ntxValCompare( pSort->pTag, (const char *) pKey, iLen, (const char *) pTmp, iLen, HB_TRUE ); if( i == 0 ) { if( pSort->pTag->fSortRec ) @@ -5152,7 +5152,7 @@ static void hb_ntxSortOut( LPNTXSORTINFO pSort ) } if( fUnique ) { - if( ulKey != 0 && hb_ntxValCompare( pTag, (char *) pSort->pLastKey, iLen, (char *) pKeyVal, iLen, HB_TRUE ) == 0 ) + if( ulKey != 0 && hb_ntxValCompare( pTag, (const char *) pSort->pLastKey, iLen, (const char *) pKeyVal, iLen, HB_TRUE ) == 0 ) { continue; } @@ -5166,7 +5166,7 @@ static void hb_ntxSortOut( LPNTXSORTINFO pSort ) #ifdef HB_NTX_DEBUG_EXT if( ulKey != 0 ) { - int i = hb_ntxValCompare( pTag, (char *) pSort->pLastKey, iLen, (char *) pKeyVal, iLen, HB_TRUE ); + int i = hb_ntxValCompare( pTag, (const char *) pSort->pLastKey, iLen, (const char *) pKeyVal, iLen, HB_TRUE ); if( ! pTag->AscendKey ) i = -i; if( i == 0 ) @@ -6301,7 +6301,7 @@ static HB_ERRCODE hb_ntxOrderCreate( NTXAREAP pArea, LPDBORDERCREATEINFO pOrderI fTemporary = pArea->dbfarea.area.lpdbOrdCondInfo->fTemporary; fExclusive = pArea->dbfarea.area.lpdbOrdCondInfo->fExclusive; /* Check conditional expression */ - szFor = ( char * ) pArea->dbfarea.area.lpdbOrdCondInfo->abFor; + szFor = pArea->dbfarea.area.lpdbOrdCondInfo->abFor; if( pArea->dbfarea.area.lpdbOrdCondInfo->itmCobFor ) /* If we have a codeblock for the conditional expression, use it */ pForExp = hb_itemNew( pArea->dbfarea.area.lpdbOrdCondInfo->itmCobFor );