[PATCH 0/1] MR7316: win32u: Avoid using uninitialized variable.
When dlls/win32u fails to load/initialize the \`FreeType font library', a device context object ends up with the only GDI driver attached -- `null_driver`. The latter implements the `pGetTextMetrics` callback function as do-nothing code. This causes the `NtGdiGetTextMetricsW()` function to fail not modifying fields of its `metrics` argument. In result the `normalize_nonclientmetrics()` ends up with uninitialized `tm` local variable after call to the `get_text_metr_size()` function. Using uninitialized fields of the `TEXTMETRICW` structure gives unpredictable results. This memset(3)'s the `tm` structure before using. After that, even if we failed to load the \`FreeType font library', the \`CaptionHeight', \`SmCaptionHeight' and \`MenuHeight' metrics keep their current values (the `normalize_nonclientmetrics()` function is called after `get_twips_entry()` callback function, thus value of an entry should not be negative). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/7316
From: Ruslan Garipov <ruslanngaripov(a)gmail.com> When dlls/win32u fails to load/initialize the `FreeType font library', a device context object ends up with the only GDI driver attached -- null_driver. The latter implements the pGetTextMetrics callback function as do-nothing code. This causes the NtGdiGetTextMetricsW() function to fail not modifying fields of its 'metrics' argument. In result the normalize_nonclientmetrics() ends up with uninitialized tm local variable after call to the get_text_metr_size() function. Using uninitialized fields of the TEXTMETRICW structure gives unpredictable results. This memset(3)'s the tm structure before using. After that, even if we failed to load the `FreeType font library', the `CaptionHeight', `SmCaptionHeight' and `MenuHeight' metrics keep their current values (the normalize_nonclientmetrics() function is called after get_twips_entry() callback function, thus value of an entry should not be negative). Signed-off-by: Ruslan Garipov <ruslanngaripov(a)gmail.com> --- dlls/win32u/sysparams.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index f58bfe14ca2..f911bc542a7 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -4910,6 +4910,7 @@ static void normalize_nonclientmetrics( NONCLIENTMETRICSW *pncm) if( pncm->iScrollHeight < 8) pncm->iScrollHeight = 8; /* adjust some heights to the corresponding font */ + memset( &tm, 0, sizeof tm ); get_text_metr_size( hdc, &pncm->lfMenuFont, &tm, NULL); pncm->iMenuHeight = max( pncm->iMenuHeight, 2 + tm.tmHeight + tm.tmExternalLeading ); get_text_metr_size( hdc, &pncm->lfCaptionFont, &tm, NULL); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/7316
participants (2)
-
Ruslan Garipov -
Ruslan Garipov (@ruslangaripov)