From a1c66499bf6b93bc2c027b5786fe73615b1f8fb7 Mon Sep 17 00:00:00 2001 From: Wim Lewis Date: Fri, 2 Oct 2009 15:23:34 -0700 Subject: [PATCH] winex11: Fix font metric cache filename generation. Recognize Mac OS X's launchd pathnames as being local. Avoid generating an invalid pathname if $DISPLAY contains slashes. Don't include the screen number in the cache filename. --- dlls/winex11.drv/xfont.c | 54 +++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/dlls/winex11.drv/xfont.c b/dlls/winex11.drv/xfont.c index f761e9b1ce8..5e160cc55a4 100644 --- a/dlls/winex11.drv/xfont.c +++ b/dlls/winex11.drv/xfont.c @@ -1830,18 +1830,10 @@ static char* XFONT_UserMetricsCache( char* buffer, int* buf_size ) const char *confdir = wine_get_config_dir(); const char *display_name = XDisplayName(NULL); int len = strlen(confdir) + strlen(INIFontMetrics) + strlen(display_name) + 8; - int display = 0; - int screen = 0; + unsigned int display = 0; + unsigned int screen = 0; char *p, *ext; - /* - ** Normalize the display name, since on Red Hat systems, DISPLAY - ** is commonly set to one of either 'unix:0.0' or ':0' or ':0.0'. - ** after this code, all of the above will resolve to ':0.0'. - */ - if (!strncmp( display_name, "unix:", 5 )) display_name += 4; - p = strchr(display_name, ':'); - if (p) sscanf(p + 1, "%d.%d", &display, &screen); if ((len > *buf_size) && !(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, *buf_size = len ))) @@ -1854,8 +1846,46 @@ static char* XFONT_UserMetricsCache( char* buffer, int* buf_size ) ext = buffer + strlen(buffer); strcpy( ext, display_name ); - if (!(p = strchr( ext, ':' ))) p = ext + strlen(ext); - sprintf( p, ":%d.%d", display, screen ); + /* + ** Normalize the display name. The format of DISPLAY is + ** [protocol/] [hostname] :[:] num [.num] + ** + ** - on Red Hat systems, DISPLAY is commonly set to one of + ** either 'unix:0.0' or ':0' or ':0.0'. + ** - on MacOS X systems, DISPLAY is commonly set to + ** /tmp/foo/:0 + ** + ** after this code, all of the above will resolve to ':0.0'. + */ + p = strrchr(ext, ':'); + if (p) + { + sscanf(p + 1, "%u.%u", &display, &screen); + *p = 0; + if (display > 9999) + { + WARN("unlikely X11 display number\n"); + *buffer = 0; + return buffer; + } + } + if (!strcmp( ext, "unix" ) || + !strcmp( ext, "localhost" )) + *ext = 0; + if (!strncmp( ext, "/tmp/", 5 )) + *ext = 0; /* assume pathnames are local */ + + /* Deal with the possibility of slashes in the display name */ + for( p = ext; *p; p++ ) + if ( *p == '/' ) + *p = '_'; + + /* X11 fonts are per-display, not per-screen, so don't + ** include the screen number in the font cache filename */ + sprintf( ext + strlen(ext), ":%u", display ); + + TRACE("display '%s' -> cachefile '%s'\n", display_name, buffer); + return buffer; }