mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 00:14:11 +09:00
Merge pull request #12271 from tsz8899/feat/memory-safety-enhanced-recommit
[client,windows] Enhance memory safety with NULL checks and resource protection
This commit is contained in:
@@ -418,6 +418,12 @@ static BOOL wf_post_connect(freerdp* instance)
|
||||
wf_image_new(wfc, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
||||
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight), format, NULL);
|
||||
|
||||
if (!wfc->primary)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to allocate primary surface");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gdi_init_ex(instance, format, 0, wfc->primary->pdata, NULL))
|
||||
return FALSE;
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ static wfBitmap* wf_glyph_new(wfContext* wfc, GLYPH_DATA* glyph)
|
||||
{
|
||||
wfBitmap* glyph_bmp;
|
||||
glyph_bmp = wf_image_new(wfc, glyph->cx, glyph->cy, PIXEL_FORMAT_MONO, glyph->aj);
|
||||
if (!glyph_bmp)
|
||||
WLog_ERR(TAG, "wf_image_new failed for glyph");
|
||||
return glyph_bmp;
|
||||
}
|
||||
|
||||
@@ -131,6 +133,11 @@ static BYTE* wf_glyph_convert(wfContext* wfc, int width, int height, const BYTE*
|
||||
const int src_bytes_per_row = (width + 7) / 8;
|
||||
const int dst_bytes_per_row = src_bytes_per_row + (src_bytes_per_row % 2);
|
||||
BYTE* cdata = (BYTE*)malloc(dst_bytes_per_row * height);
|
||||
if (!cdata)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed for cdata buffer");
|
||||
return NULL;
|
||||
}
|
||||
const BYTE* src = data;
|
||||
|
||||
for (int indexy = 0; indexy < height; indexy++)
|
||||
@@ -654,6 +661,7 @@ static BOOL wf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
|
||||
|
||||
static BOOL wf_gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
|
||||
{
|
||||
BOOL rc = FALSE;
|
||||
int org_rop2;
|
||||
HPEN hpen;
|
||||
HPEN org_hpen;
|
||||
@@ -677,6 +685,11 @@ static BOOL wf_gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
|
||||
int numPoints;
|
||||
numPoints = polyline->numDeltaEntries + 1;
|
||||
pts = (POINT*)malloc(sizeof(POINT) * numPoints);
|
||||
if (!pts)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed for polyline points");
|
||||
goto fail;
|
||||
}
|
||||
pts[0].x = temp.x = polyline->xStart;
|
||||
pts[0].y = temp.y = polyline->yStart;
|
||||
|
||||
@@ -696,10 +709,13 @@ static BOOL wf_gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
|
||||
free(pts);
|
||||
}
|
||||
|
||||
rc = TRUE;
|
||||
|
||||
fail:
|
||||
SelectObject(wfc->drawing->hdc, org_hpen);
|
||||
wf_set_rop2(wfc->drawing->hdc, org_rop2);
|
||||
DeleteObject(hpen);
|
||||
return TRUE;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static BOOL wf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
|
||||
|
||||
@@ -68,10 +68,14 @@ HBITMAP wf_create_dib(wfContext* wfc, UINT32 width, UINT32 height, UINT32 srcFor
|
||||
|
||||
wfBitmap* wf_image_new(wfContext* wfc, UINT32 width, UINT32 height, UINT32 format, const BYTE* data)
|
||||
{
|
||||
HDC hdc;
|
||||
wfBitmap* image;
|
||||
hdc = GetDC(NULL);
|
||||
image = (wfBitmap*)malloc(sizeof(wfBitmap));
|
||||
wfBitmap* image = (wfBitmap*)malloc(sizeof(wfBitmap));
|
||||
if (!image)
|
||||
{
|
||||
WLog_ERR(TAG, "malloc failed for wfBitmap");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HDC hdc = GetDC(NULL);
|
||||
image->hdc = CreateCompatibleDC(hdc);
|
||||
image->bitmap = wf_create_dib(wfc, width, height, format, data, &(image->pdata));
|
||||
image->org_bitmap = (HBITMAP)SelectObject(image->hdc, image->bitmap);
|
||||
|
||||
Reference in New Issue
Block a user