Merge branch 'asan-wineeps.drv' into 'master'

wineps.drv: Use locale aware variants _sprintf_l and _sscanf_l. (ASan)

See merge request wine/wine!6787
This commit is contained in:
Bernhard Übelacker 2024-11-19 16:50:37 +00:00
commit e4282c8d96
6 changed files with 28 additions and 32 deletions

View file

@ -21,6 +21,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <locale.h>
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
@ -87,6 +88,7 @@ static const PSDRV_DEVMODE DefaultDevmode =
HINSTANCE PSDRV_hInstance = 0; HINSTANCE PSDRV_hInstance = 0;
HANDLE PSDRV_Heap = 0; HANDLE PSDRV_Heap = 0;
_locale_t c_locale;
static BOOL import_ntf_from_reg(void) static BOOL import_ntf_from_reg(void)
{ {
@ -294,6 +296,7 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
{ {
PSDRV_hInstance = hinst; PSDRV_hInstance = hinst;
DisableThreadLibraryCalls(hinst); DisableThreadLibraryCalls(hinst);
c_locale = _create_locale( LC_ALL, "C" );
if (__wine_init_unix_call()) if (__wine_init_unix_call())
return FALSE; return FALSE;
@ -319,6 +322,7 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
if (reserved) break; if (reserved) break;
WINE_UNIX_CALL(unix_free_printer_info, NULL); WINE_UNIX_CALL(unix_free_printer_info, NULL);
_free_locale( c_locale );
HeapDestroy( PSDRV_Heap ); HeapDestroy( PSDRV_Heap );
break; break;
} }

View file

@ -884,10 +884,7 @@ PPD *PSDRV_ParsePPD( const WCHAR *fname, HANDLE printer )
#define PIA page->ImageableArea #define PIA page->ImageableArea
if(!PIA) { if(!PIA) {
PIA = HeapAlloc( PSDRV_Heap, 0, sizeof(*PIA) ); PIA = HeapAlloc( PSDRV_Heap, 0, sizeof(*PIA) );
push_lc_numeric("C"); _sscanf_l(tuple.value, "%f%f%f%f", c_locale, &PIA->llx, &PIA->lly, &PIA->urx, &PIA->ury);
sscanf(tuple.value, "%f%f%f%f", &PIA->llx, &PIA->lly,
&PIA->urx, &PIA->ury);
pop_lc_numeric();
} }
#undef PIA #undef PIA
} }
@ -908,9 +905,7 @@ PPD *PSDRV_ParsePPD( const WCHAR *fname, HANDLE printer )
#define PD page->PaperDimension #define PD page->PaperDimension
if(!PD) { if(!PD) {
PD = HeapAlloc( PSDRV_Heap, 0, sizeof(*PD) ); PD = HeapAlloc( PSDRV_Heap, 0, sizeof(*PD) );
push_lc_numeric("C"); _sscanf_l(tuple.value, "%f%f", c_locale, &PD->x, &PD->y);
sscanf(tuple.value, "%f%f", &PD->x, &PD->y);
pop_lc_numeric();
} }
#undef PD #undef PD
} }

View file

@ -625,9 +625,7 @@ BOOL PSDRV_WriteArc(print_ctx *ctx, INT x, INT y, INT w, INT h, double ang1,
/* Make angles -ve and swap order because we're working with an upside /* Make angles -ve and swap order because we're working with an upside
down y-axis */ down y-axis */
push_lc_numeric("C"); _sprintf_l(buf, psarc, c_locale, x, y, w, h, -ang2, -ang1);
sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
pop_lc_numeric();
return PSDRV_WriteSpool(ctx, buf, strlen(buf)); return PSDRV_WriteSpool(ctx, buf, strlen(buf));
} }
@ -678,16 +676,11 @@ BOOL PSDRV_WriteSetColor(print_ctx *ctx, PSCOLOR *color)
switch(color->type) { switch(color->type) {
case PSCOLOR_RGB: case PSCOLOR_RGB:
push_lc_numeric("C"); _sprintf_l(buf, pssetrgbcolor, c_locale, color->value.rgb.r, color->value.rgb.g, color->value.rgb.b);
sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
color->value.rgb.b);
pop_lc_numeric();
return PSDRV_WriteSpool(ctx, buf, strlen(buf)); return PSDRV_WriteSpool(ctx, buf, strlen(buf));
case PSCOLOR_GRAY: case PSCOLOR_GRAY:
push_lc_numeric("C"); _sprintf_l(buf, pssetgray, c_locale, color->value.gray.i);
sprintf(buf, pssetgray, color->value.gray.i);
pop_lc_numeric();
return PSDRV_WriteSpool(ctx, buf, strlen(buf)); return PSDRV_WriteSpool(ctx, buf, strlen(buf));
default: default:
@ -786,9 +779,7 @@ BOOL PSDRV_WriteRotate(print_ctx *ctx, float ang)
{ {
char buf[256]; char buf[256];
push_lc_numeric("C"); _sprintf_l(buf, psrotate, c_locale, ang);
sprintf(buf, psrotate, ang);
pop_lc_numeric();
return PSDRV_WriteSpool(ctx, buf, strlen(buf)); return PSDRV_WriteSpool(ctx, buf, strlen(buf));
} }

View file

@ -544,13 +544,7 @@ extern DWORD ASCII85_encode(BYTE *in_buf, DWORD len, BYTE *out_buf);
extern void passthrough_enter(print_ctx *ctx); extern void passthrough_enter(print_ctx *ctx);
extern void passthrough_leave(print_ctx *ctx); extern void passthrough_leave(print_ctx *ctx);
#define push_lc_numeric(x) do { \ extern _locale_t c_locale;
const char *tmplocale = setlocale(LC_NUMERIC,NULL); \
setlocale(LC_NUMERIC,x);
#define pop_lc_numeric() \
setlocale(LC_NUMERIC,tmplocale); \
} while (0)
static inline WCHAR *strdupW( const WCHAR *str ) static inline WCHAR *strdupW( const WCHAR *str )
{ {

View file

@ -203,11 +203,9 @@ TYPE42 *T42_download_header(print_ctx *ctx, char *ps_name,
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(start) + strlen(ps_name) + buf = HeapAlloc(GetProcessHeap(), 0, sizeof(start) + strlen(ps_name) +
100); 100);
push_lc_numeric("C"); _sprintf_l(buf, start, c_locale, ps_name,
sprintf(buf, start, ps_name, (float)bbox->left / emsize, (float)bbox->bottom / emsize,
(float)bbox->left / emsize, (float)bbox->bottom / emsize, (float)bbox->right / emsize, (float)bbox->top / emsize);
(float)bbox->right / emsize, (float)bbox->top / emsize);
pop_lc_numeric();
PSDRV_WriteSpool(ctx, buf, strlen(buf)); PSDRV_WriteSpool(ctx, buf, strlen(buf));

View file

@ -326,6 +326,19 @@ static inline int __cdecl printf_s(const char *format, ...)
return ret; return ret;
} }
static inline int __cdecl _sprintf_l(char *buffer, const char *format, _locale_t locale, ...) __WINE_CRT_PRINTF_ATTR(2, 4);
static inline int __cdecl _sprintf_l(char *buffer, const char *format, _locale_t locale, ...)
{
int ret;
va_list args;
va_start(args, locale);
ret = __stdio_common_vsprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION,
buffer, -1, format, locale, args);
va_end(args);
return ret < 0 ? -1 : ret;
}
static inline int __cdecl sscanf(const char *buffer, const char *format, ...) __WINE_CRT_SCANF_ATTR(2, 3); static inline int __cdecl sscanf(const char *buffer, const char *format, ...) __WINE_CRT_SCANF_ATTR(2, 3);
static inline int __cdecl sscanf(const char *buffer, const char *format, ...) static inline int __cdecl sscanf(const char *buffer, const char *format, ...)
{ {
@ -519,6 +532,7 @@ static inline int __cdecl sprintf(char *buffer, const char *format, ...)
_ACRTIMP int __cdecl snprintf(char*,size_t,const char*,...) __WINE_CRT_PRINTF_ATTR(3, 4); _ACRTIMP int __cdecl snprintf(char*,size_t,const char*,...) __WINE_CRT_PRINTF_ATTR(3, 4);
_ACRTIMP int __cdecl _snprintf(char*,size_t,const char*,...) __WINE_CRT_PRINTF_ATTR(3, 4); _ACRTIMP int __cdecl _snprintf(char*,size_t,const char*,...) __WINE_CRT_PRINTF_ATTR(3, 4);
_ACRTIMP int __cdecl sprintf(char*,const char*,...) __WINE_CRT_PRINTF_ATTR(2, 3); _ACRTIMP int __cdecl sprintf(char*,const char*,...) __WINE_CRT_PRINTF_ATTR(2, 3);
_ACRTIMP int __cdecl _sprintf_l(char*,const char*,_locale_t,...) __WINE_CRT_PRINTF_ATTR(2, 4);
#endif /* !_NO_CRT_STDIO_INLINE */ #endif /* !_NO_CRT_STDIO_INLINE */