diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ea00e0ba8e..327011064c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,27 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-12 16:44 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * src/common/hbstr.c + * Formatting. + + * contrib/hbwin/win_prn3.c + + Added static versions of strlen and strncat working on TCHARs, + to replace lstrlen(), lstrcat() unsafe calls. + + * contrib/hbnetio/utils/netiosrv.prg + + Option renamed: -addr= -> -iface= + + Added warning for unknown options. + + * contrib/hbnetio/tests/netiot02.prg + + Date setup. + + * contrib/hbcurl/hbcurl.c + * contrib/hbssl/ssl.c + * contrib/hbssl/pem.c + ! Wrapped hb_vmEvalBlockV() calls between hb_vmRequestReender() + and hb_vmRequestRestore() call pairs. + 2010-01-12 15:21 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/examples/gtwvw/gtwvw.c * updated to use hbgtreg.h to register the GT @@ -1116,7 +1137,7 @@ IsBadWritePtr(), IsBadReadPtr(), lstrlen(), lstrcpy(), lstrcat() ; QUESTION: Any idea how to fix that? win_prn3.c can probably be fixed with some good general coding - idea. + idea. [DONE: lstrlen(), lstrcpy(), lstrcat()] * contrib/hbwin/wce_smsc.c ! Fixed to not use unsafe CRTL functions. diff --git a/harbour/contrib/hbcurl/hbcurl.c b/harbour/contrib/hbcurl/hbcurl.c index 4269758776..e6ea3b05ec 100644 --- a/harbour/contrib/hbcurl/hbcurl.c +++ b/harbour/contrib/hbcurl/hbcurl.c @@ -340,16 +340,21 @@ static int hb_curl_progress_callback( void * Cargo, double dltotal, double dlnow { if( Cargo ) { - PHB_ITEM p1 = hb_itemPutND( NULL, ulnow > 0 ? ulnow : dlnow ); - PHB_ITEM p2 = hb_itemPutND( NULL, ultotal > 0 ? ultotal : dltotal ); + if( hb_vmRequestReenter() ) + { + PHB_ITEM p1 = hb_itemPutND( NULL, ulnow > 0 ? ulnow : dlnow ); + PHB_ITEM p2 = hb_itemPutND( NULL, ultotal > 0 ? ultotal : dltotal ); - HB_BOOL bResult = hb_itemGetL( hb_vmEvalBlockV( ( PHB_ITEM ) Cargo, 2, p1, p2 ) ); + HB_BOOL bResult = hb_itemGetL( hb_vmEvalBlockV( ( PHB_ITEM ) Cargo, 2, p1, p2 ) ); - hb_itemRelease( p1 ); - hb_itemRelease( p2 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); - if( bResult ) - return 1; /* Abort */ + if( bResult ) + return 1; /* Abort */ + + hb_vmRequestRestore(); + } } return 0; diff --git a/harbour/contrib/hbnetio/tests/netiot02.prg b/harbour/contrib/hbnetio/tests/netiot02.prg index 746aba359b..8a8b131b25 100644 --- a/harbour/contrib/hbnetio/tests/netiot02.prg +++ b/harbour/contrib/hbnetio/tests/netiot02.prg @@ -53,6 +53,9 @@ proc main() + SET DATE ANSI + SET CENTURY ON + /* connect to the server */ ? "CONNECTING..." ? "NETIO_CONNECT():", netio_connect( NETSERVER, NETPORT,, NETPASSWD ) diff --git a/harbour/contrib/hbnetio/utils/netiosrv.prg b/harbour/contrib/hbnetio/utils/netiosrv.prg index c73245fae5..4b01c8580e 100644 --- a/harbour/contrib/hbnetio/utils/netiosrv.prg +++ b/harbour/contrib/hbnetio/utils/netiosrv.prg @@ -34,8 +34,8 @@ PROCEDURE Main( ... ) DO CASE CASE Lower( Left( cParam, 6 ) ) == "-port=" port := Val( SubStr( cParam, 7 ) ) - CASE Lower( Left( cParam, 6 ) ) == "-addr=" - ifaddr := SubStr( cParam, 7 ) + CASE Lower( Left( cParam, 7 ) ) == "-iface=" + ifaddr := SubStr( cParam, 8 ) CASE Lower( Left( cParam, 9 ) ) == "-rootdir=" rootdir := SubStr( cParam, 10 ) CASE Lower( Left( cParam, 6 ) ) == "-pass=" @@ -46,6 +46,8 @@ PROCEDURE Main( ... ) Lower( cParam ) == "--help" HB_Usage() RETURN + OTHERWISE + OutStd( "Warning: Unkown parameter ignored: " + cParam + hb_osNewLine() ) ENDCASE NEXT @@ -79,7 +81,7 @@ STATIC PROCEDURE HB_Logo() STATIC PROCEDURE HB_Usage() - OutStd( "Syntax: netiosrv [-port=] [-addr=] [-rootdir=] [-rpc] [-pass=]" + hb_osNewLine() ) + OutStd( "Syntax: netiosrv [-port=] [-iface=] [-rootdir=] [-rpc] [-pass=]" + hb_osNewLine() ) RETURN diff --git a/harbour/contrib/hbssl/pem.c b/harbour/contrib/hbssl/pem.c index d5a1d8d5b0..1b44f7257a 100644 --- a/harbour/contrib/hbssl/pem.c +++ b/harbour/contrib/hbssl/pem.c @@ -64,7 +64,7 @@ static int hb_ssl_pem_password_cb( char * buf, int size, int rwflag, void * user { int retsize = 0; - if( size > 0 && userdata ) + if( size > 0 && userdata && hb_vmRequestReenter() ) { PHB_ITEM p = hb_itemPutL( NULL, rwflag ); PHB_ITEM r = hb_vmEvalBlockV( ( PHB_ITEM ) userdata, 1, p ); @@ -82,6 +82,8 @@ static int hb_ssl_pem_password_cb( char * buf, int size, int rwflag, void * user memcpy( buf, hb_itemGetCPtr( r ), retsize ); } + + hb_vmRequestRestore(); } return retsize; diff --git a/harbour/contrib/hbssl/ssl.c b/harbour/contrib/hbssl/ssl.c index b4b67796da..e2bccf269e 100644 --- a/harbour/contrib/hbssl/ssl.c +++ b/harbour/contrib/hbssl/ssl.c @@ -1478,7 +1478,7 @@ static void hb_ssl_msg_callback( int write_p, int version, int content_type, con { HB_SYMBOL_UNUSED( ssl ); - if( userdata ) + if( userdata && hb_vmRequestReenter() ) { PHB_ITEM p1 = hb_itemPutL( NULL, write_p ); PHB_ITEM p2 = hb_itemPutNI( NULL, version ); @@ -1491,6 +1491,8 @@ static void hb_ssl_msg_callback( int write_p, int version, int content_type, con hb_itemRelease( p3 ); hb_itemRelease( p2 ); hb_itemRelease( p1 ); + + hb_vmRequestRestore(); } } diff --git a/harbour/contrib/hbwin/win_prn3.c b/harbour/contrib/hbwin/win_prn3.c index 17489eb9fb..8df3d9b6b7 100644 --- a/harbour/contrib/hbwin/win_prn3.c +++ b/harbour/contrib/hbwin/win_prn3.c @@ -66,6 +66,39 @@ #include "hbapi.h" #include "hbwinuni.h" +/* NOTE: Based on hb_strncat() */ +static TCHAR * hb_tstrncat( TCHAR * pDest, const TCHAR * pSource, ULONG ulLen ) +{ + TCHAR * pBuf = pDest; + + HB_TRACE(HB_TR_DEBUG, ("hb_tstrncat(%p, %p, %lu)", pDest, pSource, ulLen)); + + pDest[ ulLen ] = '\0'; + + while( ulLen && *pDest ) + { + pDest++; + ulLen--; + } + + while( ulLen && ( *pDest++ = *pSource++ ) != '\0' ) + ulLen--; + + return pBuf; +} + +static ULONG hb_tstrlen( const TCHAR * pText ) +{ + ULONG ul = 0; + + HB_TRACE(HB_TR_DEBUG, ("hb_tstrlen(%p)", pText)); + + while( pText[ ul ] ) + ++ul; + + return ul; +} + static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) { BOOL bFlag; @@ -161,6 +194,8 @@ static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) } else /* NT4.0 or earlier */ { + int nStrLen; + /* Open this printer so you can get information about it. */ bFlag = OpenPrinter( ( LPTSTR ) lpPrinterName, &hPrinter, NULL ); if( ! bFlag || ! hPrinter ) @@ -194,23 +229,22 @@ static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) return HB_FALSE; } - /* TOFIX: Use safe string functions instead of lstrlen() and lstrcat(). - [vszakats] */ + nStrLen = hb_tstrlen( lpPrinterName ) + + hb_tstrlen( ppi2->pDriverName ) + + hb_tstrlen( ppi2->pPortName ) + 2; /* Allocate buffer big enough for concatenated string. String will be in form "printername,drivername,portname". */ - pBuffer = ( LPTSTR ) hb_xgrab( ( lstrlen( lpPrinterName ) + - lstrlen( ppi2->pDriverName ) + - lstrlen( ppi2->pPortName ) + 3 ) * sizeof( TCHAR ) ); + pBuffer = ( LPTSTR ) hb_xgrab( ( nStrLen + 1 ) * sizeof( TCHAR ) ); pBuffer[ 0 ] = '\0'; /* Build string in form "printername,drivername,portname". */ - lstrcat( pBuffer, lpPrinterName ); - lstrcat( pBuffer, TEXT( "," ) ); - lstrcat( pBuffer, ppi2->pDriverName ); - lstrcat( pBuffer, TEXT( "," ) ); - lstrcat( pBuffer, ppi2->pPortName ); + hb_tstrncat( pBuffer, lpPrinterName, nStrLen ); + hb_tstrncat( pBuffer, TEXT( "," ), nStrLen ); + hb_tstrncat( pBuffer, ppi2->pDriverName, nStrLen ); + hb_tstrncat( pBuffer, TEXT( "," ), nStrLen ); + hb_tstrncat( pBuffer, ppi2->pPortName, nStrLen ); /* Set the default printer in win.ini and registry. */ bFlag = WriteProfileString( TEXT( "windows" ), TEXT( "device" ), pBuffer ); diff --git a/harbour/src/common/hbstr.c b/harbour/src/common/hbstr.c index 7d242acc89..63bfb1271f 100644 --- a/harbour/src/common/hbstr.c +++ b/harbour/src/common/hbstr.c @@ -227,7 +227,7 @@ ULONG hb_strlentrim( const char * pszText ) while( pszText[ 0 ] == ' ' ) ++pszText; - while( pszText[ ul] ) + while( pszText[ ul ] ) ++ul; while( ul && pszText[ ul - 1 ] == ' ' ) @@ -795,7 +795,7 @@ char * hb_numToStr( char * szBuf, ULONG ulSize, HB_LONG lNumber ) */ char * hb_strncpy( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; HB_TRACE(HB_TR_DEBUG, ("hb_strncpy(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -814,7 +814,7 @@ char * hb_strncpy( char * pDest, const char * pSource, ULONG ulLen ) */ char * hb_strncat( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; HB_TRACE(HB_TR_DEBUG, ("hb_strncat(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -841,7 +841,7 @@ char * hb_strncat( char * pDest, const char * pSource, ULONG ulLen ) */ char * hb_strncpyLower( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; HB_TRACE(HB_TR_DEBUG, ("hb_strncpyLower(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -865,7 +865,7 @@ char * hb_strncpyLower( char * pDest, const char * pSource, ULONG ulLen ) */ char * hb_strncpyUpper( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpper(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -889,7 +889,7 @@ char * hb_strncpyUpper( char * pDest, const char * pSource, ULONG ulLen ) */ char * hb_strncpyUpperTrim( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; ULONG ulSLen; HB_TRACE(HB_TR_DEBUG, ("hb_strncpyUpperTrim(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -921,7 +921,7 @@ char * hb_strncpyUpperTrim( char * pDest, const char * pSource, ULONG ulLen ) */ char * hb_strncpyTrim( char * pDest, const char * pSource, ULONG ulLen ) { - char *pBuf = pDest; + char * pBuf = pDest; ULONG ulSLen; HB_TRACE(HB_TR_DEBUG, ("hb_strncpyTrim(%p, %s, %lu)", pDest, pSource, ulLen)); @@ -946,8 +946,8 @@ char * hb_strncpyTrim( char * pDest, const char * pSource, ULONG ulLen ) char * hb_strRemEscSeq( char *str, ULONG *pLen ) { - ULONG ul = *pLen, ulStripped = 0; - char *ptr, *dst, ch; + ULONG ul = * pLen, ulStripped = 0; + char * ptr, * dst, ch; ptr = dst = str; while( ul )