From 29de7dd60ba27c7aa79f455b4f4bc9c56c8292d0 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Fri, 20 Dec 2013 05:55:34 +0100 Subject: [PATCH] ntdll: Handle error if RtlAllocateHeap fails in printf functions. --- dlls/ntdll/printf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/printf.c b/dlls/ntdll/printf.c index 49d39833ec7..3a5067ad32e 100644 --- a/dlls/ntdll/printf.c +++ b/dlls/ntdll/printf.c @@ -300,7 +300,13 @@ static void pf_integer_conv( char *buf, int buf_len, pf_flags *flags, char number[40], *tmp = number; if( buf_len > sizeof number ) - tmp = RtlAllocateHeap( GetProcessHeap(), 0, buf_len ); + { + if (!(tmp = RtlAllocateHeap( GetProcessHeap(), 0, buf_len ))) + { + buf[0] = '\0'; + return; + } + } base = 10; if( flags->Format == 'o' ) @@ -588,7 +594,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis flags.FieldLength : flags.Precision) + 10; if( x_len >= sizeof number) - x = RtlAllocateHeap( GetProcessHeap(), 0, x_len ); + if (!(x = RtlAllocateHeap( GetProcessHeap(), 0, x_len ))) + return -1; pf_integer_conv( x, x_len, &flags, va_arg(valist, LONGLONG) ); @@ -611,7 +618,8 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis flags.FieldLength : flags.Precision) + 10; if( x_len >= sizeof number) - x = RtlAllocateHeap( GetProcessHeap(), 0, x_len ); + if (!(x = RtlAllocateHeap( GetProcessHeap(), 0, x_len ))) + return -1; pf_rebuild_format_string( fmt, &flags );