Commit b9755cd0 authored by Jean-Paul Saman's avatar Jean-Paul Saman

dr_56: add boundary checking

parent e9df3130
...@@ -62,15 +62,16 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr( ...@@ -62,15 +62,16 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
if(p_descriptor->i_length % 5) if(p_descriptor->i_length % 5)
return NULL; return NULL;
int i_pages_number;
i_pages_number = p_descriptor->i_length / 5;
/* Allocate memory */ /* Allocate memory */
dvbpsi_teletext_dr_t * p_decoded; dvbpsi_teletext_dr_t * p_decoded;
p_decoded = (dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t)); p_decoded = (dvbpsi_teletext_dr_t*)malloc(sizeof(dvbpsi_teletext_dr_t));
if (!p_decoded) if (!p_decoded)
return NULL; return NULL;
int i_pages_number;
i_pages_number = p_descriptor->i_length / 5;
if (i_pages_number > DVBPSI_TELETEXT_DR_MAX)
i_pages_number = DVBPSI_TELETEXT_DR_MAX;
p_decoded->i_pages_number = i_pages_number; p_decoded->i_pages_number = i_pages_number;
for (int i = 0; i < i_pages_number; i++) for (int i = 0; i < i_pages_number; i++)
...@@ -99,6 +100,9 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr( ...@@ -99,6 +100,9 @@ dvbpsi_teletext_dr_t * dvbpsi_DecodeTeletextDr(
dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(dvbpsi_teletext_dr_t * p_decoded, dvbpsi_descriptor_t * dvbpsi_GenTeletextDr(dvbpsi_teletext_dr_t * p_decoded,
bool b_duplicate) bool b_duplicate)
{ {
if (p_decoded->i_pages_number > DVBPSI_TELETEXT_DR_MAX)
p_decoded->i_pages_number = DVBPSI_TELETEXT_DR_MAX;
/* Create the descriptor */ /* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x56, p_decoded->i_pages_number * 8 , NULL); dvbpsi_NewDescriptor(0x56, p_decoded->i_pages_number * 8 , NULL);
......
...@@ -62,6 +62,12 @@ typedef struct dvbpsi_teletextpage_s ...@@ -62,6 +62,12 @@ typedef struct dvbpsi_teletextpage_s
} dvbpsi_teletextpage_t; } dvbpsi_teletextpage_t;
/*!
* \def DVBPSI_TELETEXT_DR_MAX
* \brief Maximum number of dvbpsi_teletextpage_t entries present in
* @see dvbpsi_teletext_dr_t
*/
#define DVBPSI_TELETEXT_DR_MAX 64
/***************************************************************************** /*****************************************************************************
* dvbpsi_teletext_dr_t * dvbpsi_teletext_dr_t
...@@ -79,12 +85,11 @@ typedef struct dvbpsi_teletextpage_s ...@@ -79,12 +85,11 @@ typedef struct dvbpsi_teletextpage_s
*/ */
typedef struct dvbpsi_teletext_dr_s typedef struct dvbpsi_teletext_dr_s
{ {
uint8_t i_pages_number; /*!< number of pages */ uint8_t i_pages_number; /*!< number of pages */
dvbpsi_teletextpage_t p_pages[64]; /*!< teletext pages */ dvbpsi_teletextpage_t p_pages[DVBPSI_TELETEXT_DR_MAX]; /*!< teletext pages */
} dvbpsi_teletext_dr_t; } dvbpsi_teletext_dr_t;
/***************************************************************************** /*****************************************************************************
* dvbpsi_DecodeTeletextDataDr * dvbpsi_DecodeTeletextDataDr
*****************************************************************************/ *****************************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment