https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e0b9d6d9cd4e5b5e7d9a445efeae6d3dc81fd652

commit e0b9d6d9cd4e5b5e7d9a445efeae6d3dc81fd652
Author:     Raymond Czerny <[email protected]>
AuthorDate: Thu May 5 16:24:38 2022 +0200
Commit:     GitHub <[email protected]>
CommitDate: Thu May 5 16:24:38 2022 +0200

    [SHELL32] CPrinterFolder: Validate string pointers properly. (#4486)
    
    CORE-18174
    
    Check string pointers before determining the length of strings.
---
 dll/win32/shell32/folders/CPrinterFolder.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/dll/win32/shell32/folders/CPrinterFolder.cpp 
b/dll/win32/shell32/folders/CPrinterFolder.cpp
index 0f437ea5cef..43050b625c9 100644
--- a/dll/win32/shell32/folders/CPrinterFolder.cpp
+++ b/dll/win32/shell32/folders/CPrinterFolder.cpp
@@ -102,10 +102,13 @@ static LPITEMIDLIST _ILCreatePrinterItem(PRINTER_INFO_4W 
*pi)
     PIDLPrinterStruct * p;
     int size0 = (char*)&tmp.u.cprinter.szName - (char*)&tmp.u.cprinter;
     int size = size0;
-    SIZE_T cchPrinterName, cchServerName;
+    SIZE_T cchPrinterName = 0;
+    SIZE_T cchServerName = 0;
 
-    cchPrinterName = wcslen(pi->pPrinterName);
-    cchServerName = wcslen(pi->pServerName);
+    if (pi->pPrinterName)
+        cchPrinterName = wcslen(pi->pPrinterName);
+    if (pi->pServerName)
+        cchServerName = wcslen(pi->pServerName);
     if ((cchPrinterName + cchServerName) > (MAXUSHORT - 2))
     {
         return NULL;

Reply via email to