This makes __wine_dbg_output() slightly more robust. The change prevents the debug output buffer overflow when __wine_dbg_output() is called repeatedly with small strings.
Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
Supersedes patch 164513.
--- dlls/ntdll/debugtools.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c index 64355ab3b841..027ca0236051 100644 --- a/dlls/ntdll/debugtools.c +++ b/dlls/ntdll/debugtools.c @@ -235,6 +235,7 @@ int __cdecl __wine_dbg_output( const char *str ) struct debug_info *info = get_info(); const char *end = strrchr( str, '\n' ); int ret = 0; + size_t n;
if (end) { @@ -243,7 +244,16 @@ int __cdecl __wine_dbg_output( const char *str ) info->out_pos = 0; str = end + 1; } - if (*str) ret += append_output( info, str, strlen( str )); + if (*str) + { + n = strlen( str ); + if (n >= sizeof(info->output) - info->out_pos && info->out_pos) + { + write( 2, info->output, info->out_pos ); + info->out_pos = 0; + } + ret += append_output( info, str, n ); + } return ret; }