Added checks and asserts in rdpgfx_common

This commit is contained in:
akallabeth 2022-01-27 10:03:17 +01:00 committed by akallabeth
parent 6f154da1ae
commit 4b416968c4

View File

@ -141,8 +141,11 @@ UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header)
*/
UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header)
{
WINPR_ASSERT(s);
WINPR_ASSERT(header);
if (!Stream_EnsureRemainingCapacity(s, 8))
return ERROR_INTERNAL_ERROR;
return CHANNEL_RC_NO_MEMORY;
Stream_Write_UINT16(s, header->cmdId); /* cmdId (2 bytes) */
Stream_Write_UINT16(s, header->flags); /* flags (2 bytes) */
Stream_Write_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
@ -156,6 +159,9 @@ UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header)
*/
UINT rdpgfx_read_point16(wStream* s, RDPGFX_POINT16* pt16)
{
WINPR_ASSERT(s);
WINPR_ASSERT(pt16);
if (Stream_GetRemainingLength(s) < 4)
{
WLog_ERR(TAG, "not enough data!");
@ -174,6 +180,12 @@ UINT rdpgfx_read_point16(wStream* s, RDPGFX_POINT16* pt16)
*/
UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16)
{
WINPR_ASSERT(s);
WINPR_ASSERT(point16);
if (!Stream_EnsureRemainingCapacity(s, 4))
return CHANNEL_RC_NO_MEMORY;
Stream_Write_UINT16(s, point16->x); /* x (2 bytes) */
Stream_Write_UINT16(s, point16->y); /* y (2 bytes) */
return CHANNEL_RC_OK;
@ -186,6 +198,9 @@ UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16)
*/
UINT rdpgfx_read_rect16(wStream* s, RECTANGLE_16* rect16)
{
WINPR_ASSERT(s);
WINPR_ASSERT(rect16);
if (Stream_GetRemainingLength(s) < 8)
{
WLog_ERR(TAG, "not enough data!");
@ -210,6 +225,12 @@ UINT rdpgfx_read_rect16(wStream* s, RECTANGLE_16* rect16)
*/
UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16)
{
WINPR_ASSERT(s);
WINPR_ASSERT(rect16);
if (!Stream_EnsureRemainingCapacity(s, 8))
return CHANNEL_RC_NO_MEMORY;
Stream_Write_UINT16(s, rect16->left); /* left (2 bytes) */
Stream_Write_UINT16(s, rect16->top); /* top (2 bytes) */
Stream_Write_UINT16(s, rect16->right); /* right (2 bytes) */
@ -224,6 +245,9 @@ UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16)
*/
UINT rdpgfx_read_color32(wStream* s, RDPGFX_COLOR32* color32)
{
WINPR_ASSERT(s);
WINPR_ASSERT(color32);
if (Stream_GetRemainingLength(s) < 4)
{
WLog_ERR(TAG, "not enough data!");
@ -244,6 +268,12 @@ UINT rdpgfx_read_color32(wStream* s, RDPGFX_COLOR32* color32)
*/
UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32)
{
WINPR_ASSERT(s);
WINPR_ASSERT(color32);
if (!Stream_EnsureRemainingCapacity(s, 4))
return CHANNEL_RC_NO_MEMORY;
Stream_Write_UINT8(s, color32->B); /* B (1 byte) */
Stream_Write_UINT8(s, color32->G); /* G (1 byte) */
Stream_Write_UINT8(s, color32->R); /* R (1 byte) */