Dan Kegel : advapi32: Fix buffer overrun in tests/registry.c: wine_debugstr_wn().

Alexandre Julliard julliard at winehq.org
Mon Nov 12 06:27:47 CST 2007


Module: wine
Branch: master
Commit: 89b9af77147cfc5afdb90bafb81228cd9bc4399e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=89b9af77147cfc5afdb90bafb81228cd9bc4399e

Author: Dan Kegel <dank at kegel.com>
Date:   Sun Nov 11 06:33:03 2007 -0800

advapi32: Fix buffer overrun in tests/registry.c:wine_debugstr_wn().

---

 dlls/advapi32/tests/registry.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 017dab3..1c50d2a 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -56,7 +56,6 @@ static char *get_temp_buffer( int size )
     return ret;
 }
 
-/* default implementation of wine_dbgstr_an */
 static const char *wine_debugstr_an( const char *str, int n )
 {
     static const char hex[16] = "0123456789abcdef";
@@ -108,10 +107,10 @@ static const char *wine_debugstr_an( const char *str, int n )
     return res;
 }
 
-/* default implementation of wine_dbgstr_wn */
 static const char *wine_debugstr_wn( const WCHAR *str, int n )
 {
     char *dst, *res;
+    size_t size;
 
     if (!HIWORD(str))
     {
@@ -122,11 +121,11 @@ static const char *wine_debugstr_wn( const WCHAR *str, int n )
     }
     if (n == -1) n = lstrlenW(str);
     if (n < 0) n = 0;
-    else if (n > 200) n = 200;
+    size = 12 + min( 300, n * 5);
     dst = res = get_temp_buffer( n * 5 + 7 );
     *dst++ = 'L';
     *dst++ = '"';
-    while (n-- > 0)
+    while (n-- > 0 && dst <= res + size - 10)
     {
         WCHAR c = *str++;
         switch (c)
@@ -148,7 +147,7 @@ static const char *wine_debugstr_wn( const WCHAR *str, int n )
         }
     }
     *dst++ = '"';
-    if (*str)
+    if (n > 0)
     {
         *dst++ = '.';
         *dst++ = '.';




More information about the wine-cvs mailing list