Added plausibility checks and assert to rdpgfx_read_header
#endif
#include <winpr/crt.h>
+#include <winpr/assert.h>
#include <winpr/stream.h>
#include <freerdp/channels/log.h>
@@ -111,6 +112,9 @@ const char* rdpgfx_get_codec_id_string(UINT16 codecId)
*/
UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header)
{
+ WINPR_ASSERT(s);
+ WINPR_ASSERT(header);
+
if (Stream_GetRemainingLength(s) < 8)
{
WLog_ERR(TAG, "calloc failed!");
@@ -121,10 +125,10 @@ UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header)
Stream_Read_UINT16(s, header->flags); /* flags (2 bytes) */
Stream_Read_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
- if (header->pduLength < 8)
+ if ((header->pduLength < 8) || (Stream_GetRemainingLength(s) < (header->pduLength - 8)))
{
WLog_ERR(TAG, "header->pduLength %u less than 8!", header->pduLength);
- return CHANNEL_RC_NO_MEMORY;
+ return ERROR_INVALID_DATA;
}
return CHANNEL_RC_OK;
