From 52f4f6acefd8d027447a9f489817472e2c3ace59 Mon Sep 17 00:00:00 2001 From: Jason Filby Date: Sun, 4 Jul 2004 18:11:49 +0000 Subject: [PATCH] lstrcpy and lstrcat should return NULL if the string to copy to is NULL instead of crashing; verified by a test app on Windows XP svn path=/trunk/; revision=9998 --- reactos/lib/kernel32/string/lstring.c | 50 +++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/reactos/lib/kernel32/string/lstring.c b/reactos/lib/kernel32/string/lstring.c index c72c1dc9298..67890fcd129 100644 --- a/reactos/lib/kernel32/string/lstring.c +++ b/reactos/lib/kernel32/string/lstring.c @@ -21,7 +21,7 @@ lstrcmpA( LPCSTR lpString2 ) { - return strcmp(lpString1,lpString2); + return strcmp(lpString1,lpString2); } @@ -35,7 +35,7 @@ lstrcmpiA( LPCSTR lpString2 ) { - return _stricmp(lpString1,lpString2); + return _stricmp(lpString1,lpString2); } @@ -54,6 +54,11 @@ lstrcpynA( lpString1 with NUL bytes while lstrcpynA doesn't. Also lstrcpynA guarantees NUL termination while strncpy doesn't */ + if (lpString1 == NULL) + { + return NULL; + } + if (1 < iMaxLength) { char *d = lpString1; @@ -89,7 +94,12 @@ lstrcpyA( LPCSTR lpString2 ) { - return strcpy(lpString1,lpString2); + if (lpString1 == NULL) + { + return NULL; + } + + return strcpy(lpString1,lpString2); } @@ -103,7 +113,12 @@ lstrcatA( LPCSTR lpString2 ) { - return strcat(lpString1,lpString2); + if (lpString1 == NULL) + { + return NULL; + } + + return strcat(lpString1,lpString2); } @@ -116,7 +131,7 @@ lstrlenA( LPCSTR lpString ) { - return strlen(lpString); + return strlen(lpString); } @@ -130,7 +145,7 @@ lstrcmpW( LPCWSTR lpString2 ) { - return wcscmp(lpString1,lpString2); + return wcscmp(lpString1,lpString2); } @@ -144,7 +159,7 @@ lstrcmpiW( LPCWSTR lpString2 ) { - return _wcsicmp(lpString1,lpString2); + return _wcsicmp(lpString1,lpString2); } @@ -163,6 +178,11 @@ lstrcpynW( lpString1 with NUL bytes while lstrcpynW doesn't Also lstrcpynW guarantees NUL termination while wcsncpy doesn't */ + if (lpString1 == NULL) + { + return NULL; + } + if (1 < iMaxLength) { WCHAR *d = lpString1; @@ -198,7 +218,12 @@ lstrcpyW( LPCWSTR lpString2 ) { - return wcscpy(lpString1,lpString2); + if (lpString1 == NULL) + { + return NULL; + } + + return wcscpy(lpString1,lpString2); } @@ -212,7 +237,12 @@ lstrcatW( LPCWSTR lpString2 ) { - return wcscat(lpString1,lpString2); + if (lpString1 == NULL) + { + return NULL; + } + + return wcscat(lpString1,lpString2); } @@ -225,5 +255,5 @@ lstrlenW( LPCWSTR lpString ) { - return wcslen(lpString); + return wcslen(lpString); }