vsnprintf isn't always guaranteed to null terminate its output, depends on the version of msvcrt used.
See !8256 for more information.
supersedes !8256
-- v2: include: Make sure to null terminate string in wine_dbg_vsprintf.
From: Yuxuan Shui yshui@codeweavers.com
vsnprintf isn't always guaranteed to null terminate its output, depends on the version of msvcrt used.
See !8256 for more information. --- include/wine/debug.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/wine/debug.h b/include/wine/debug.h index 3e0912de801..17b24b65cfc 100644 --- a/include/wine/debug.h +++ b/include/wine/debug.h @@ -133,8 +133,8 @@ static const char * __wine_dbg_cdecl wine_dbg_vsprintf( const char *format, va_l static inline const char * __wine_dbg_cdecl wine_dbg_vsprintf( const char *format, va_list args ) { char buffer[200]; - - vsnprintf( buffer, sizeof(buffer), format, args ); + int len = vsnprintf( buffer, sizeof(buffer), format, args ); + if (len >= sizeof(buffer)) buffer[sizeof(buffer) - 1] = 0; return __wine_dbg_strdup( buffer ); }
@@ -154,8 +154,8 @@ static int __wine_dbg_cdecl wine_dbg_vprintf( const char *format, va_list args ) static inline int __wine_dbg_cdecl wine_dbg_vprintf( const char *format, va_list args ) { char buffer[1024]; - - vsnprintf( buffer, sizeof(buffer), format, args ); + int len = vsnprintf( buffer, sizeof(buffer), format, args ); + if (len >= sizeof(buffer)) buffer[sizeof(buffer) - 1] = 0; return __wine_dbg_output( buffer ); }