[PATCH v7 0/1] MR5854: win32u: get_char_dimensions set height to 1 when failed
Signed-off-by: Fan WenJie <fanwj(a)mail.ustc.edu.cn> when get_char_dimensions failed, width not set, width may be undefined value and cause undefined behaviour -- v7: win32u: fix random crash without libfreetype https://gitlab.winehq.org/wine/wine/-/merge_requests/5854
From: Fan WenJie <fanwj(a)mail.ustc.edu.cn> Signed-off-by: Fan WenJie <fanwj(a)mail.ustc.edu.cn> --- dlls/win32u/sysparams.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 9a06db2c7f6..9a885d182aa 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -4323,13 +4323,16 @@ LONG get_char_dimensions( HDC hdc, TEXTMETRICW *metric, int *height ) 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H', 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; - if (metric && !NtGdiGetTextMetricsW( hdc, metric, 0 )) return 0; + if (metric && !NtGdiGetTextMetricsW( hdc, metric, 0 )) goto fail; if (!NtGdiGetTextExtentExW( hdc, abcdW, ARRAYSIZE(abcdW), 0, NULL, NULL, &sz, 0 )) - return 0; + goto fail; if (height) *height = sz.cy; return (sz.cx / 26 + 1) / 2; +fail: + if (height) *height = 1; + return 0; } /* get text metrics and/or "average" char width of the specified logfont @@ -4340,6 +4343,7 @@ static void get_text_metr_size( HDC hdc, LOGFONTW *lf, TEXTMETRICW *metric, UINT TEXTMETRICW tm; UINT ret; if (!metric) metric = &tm; + memset(metric, 0, sizeof(*metric)); hfont = NtGdiHfontCreate( lf, sizeof(*lf), 0, 0, NULL ); if (!hfont || !(hfontsav = NtGdiSelectFont( hdc, hfont ))) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5854
This merge request was closed by Fan WenJie. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/5854
participants (2)
-
Fan WenJie -
Fan WenJie (@fanwenjie)