diff --git a/ChangeLog.txt b/ChangeLog.txt index 6fd01be8c9..60325b70f1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,11 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-09-23 13:18 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbcurl/core.c + ! added protection against operation on NULL pointers borrowed from + Viktor's branch. + 2014-09-23 11:41 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/gtqtc/gtqtc1.cpp * src/rtl/gtwvt/gtwvt.c diff --git a/contrib/hbcurl/core.c b/contrib/hbcurl/core.c index 212afeb205..3e6a6c97b8 100644 --- a/contrib/hbcurl/core.c +++ b/contrib/hbcurl/core.c @@ -165,19 +165,24 @@ static HB_HASH_FUNC( hb_curl_HashCmp ) static const char * hb_curl_StrHashNew( PHB_CURL hb_curl, const char * szValue ) { - char * szHash; - - if( ! hb_curl->pHash ) - hb_curl->pHash = hb_hashTableCreate( HB_CURL_HASH_TABLE_SIZE, - hb_curl_HashKey, hb_curl_HashDel, hb_curl_HashCmp ); - - szHash = ( char * ) hb_hashTableFind( hb_curl->pHash, szValue ); - if( ! szHash ) + if( szValue ) { - szHash = hb_strdup( szValue ); - hb_hashTableAdd( hb_curl->pHash, szHash, szHash ); + char * szHash; + + if( ! hb_curl->pHash ) + hb_curl->pHash = hb_hashTableCreate( HB_CURL_HASH_TABLE_SIZE, + hb_curl_HashKey, hb_curl_HashDel, hb_curl_HashCmp ); + + szHash = ( char * ) hb_hashTableFind( hb_curl->pHash, szValue ); + if( ! szHash ) + { + szHash = hb_strdup( szValue ); + hb_hashTableAdd( hb_curl->pHash, szHash, szHash ); + } + return szHash; } - return szHash; + else + return NULL; } # define hb_curl_StrHash( c, s ) hb_curl_StrHashNew( ( c ), ( s ) ) @@ -193,17 +198,18 @@ static const char * hb_curl_StrHashNew( PHB_CURL hb_curl, const char * szValue ) static void * hb_curl_xgrab( size_t size ) { - return hb_xgrab( size ); + return size > 0 ? hb_xgrab( size ) : NULL; } static void hb_curl_xfree( void * p ) { - hb_xfree( p ); + if( p ) + hb_xfree( p ); } static void * hb_curl_xrealloc( void * p, size_t size ) { - return hb_xrealloc( p, size ); + return size > 0 ? ( p ? hb_xrealloc( p, size ) : hb_xgrab( size ) ) : NULL; } static char * hb_curl_strdup( const char * s ) @@ -389,7 +395,7 @@ static int hb_curl_progress_callback( void * Cargo, double dltotal, double dlnow { hb_vmPushEvalSym(); hb_vmPush( ( PHB_ITEM ) Cargo ); - hb_vmPushDouble( ulnow > 0 ? ulnow : dlnow, HB_DEFAULT_DECIMALS ); + hb_vmPushDouble( ulnow > 0 ? ulnow : dlnow, HB_DEFAULT_DECIMALS ); hb_vmPushDouble( ultotal > 0 ? ultotal : dltotal, HB_DEFAULT_DECIMALS ); hb_vmSend( 2 );