Owen Rudge : winspool: Filter invalid characters when creating the PPD filename.

Alexandre Julliard julliard at winehq.org
Wed Mar 10 14:58:46 CST 2021


Module: wine
Branch: master
Commit: 6b906e82371513e9f5b94fa2d67ad8e0ee865335
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=6b906e82371513e9f5b94fa2d67ad8e0ee865335

Author: Owen Rudge <orudge at codeweavers.com>
Date:   Wed Mar 10 12:26:50 2021 +0000

winspool: Filter invalid characters when creating the PPD filename.

Fixes potential crash when trying to print if a CUPS printer name
contains an asterisk.

Signed-off-by: Owen Rudge <orudge at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winspool.drv/info.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index fb9c1599d38..4d0542d20e3 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -721,13 +721,18 @@ fail:
 static WCHAR *get_ppd_filename( const WCHAR *dir, const WCHAR *file_name )
 {
     static const WCHAR dot_ppd[] = {'.','p','p','d',0};
-    int len = (strlenW( dir ) + strlenW( file_name )) * sizeof(WCHAR) + sizeof(dot_ppd);
-    WCHAR *ppd = HeapAlloc( GetProcessHeap(), 0, len );
+    static const WCHAR invalid_chars[] = {'*','?','<','>','|','"','/','\\',0};
+    int dir_len = strlenW( dir ), file_len = strlenW( file_name );
+    int len = (dir_len + file_len + ARRAY_SIZE( dot_ppd )) * sizeof(WCHAR);
+    WCHAR *ppd = HeapAlloc( GetProcessHeap(), 0, len ), *p;
 
     if (!ppd) return NULL;
-    strcpyW( ppd, dir );
-    strcatW( ppd, file_name );
-    strcatW( ppd, dot_ppd );
+    memcpy( ppd, dir, dir_len * sizeof(WCHAR) );
+    memcpy( ppd + dir_len, file_name, file_len * sizeof(WCHAR) );
+    memcpy( ppd + dir_len + file_len, dot_ppd, sizeof(dot_ppd) );
+
+    p = ppd + dir_len;
+    while ((p = strpbrkW( p, invalid_chars ))) *p++ = '_';
 
     return ppd;
 }




More information about the wine-cvs mailing list