Commit 805c3910 authored by Jean-Paul Saman's avatar Jean-Paul Saman

dr_45: Add boundary checking

parent 74207500
...@@ -63,6 +63,8 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr( ...@@ -63,6 +63,8 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
/* */ /* */
dvbpsi_vbi_dr_t * p_decoded; dvbpsi_vbi_dr_t * p_decoded;
int i_services_number = p_descriptor->i_length / 2; int i_services_number = p_descriptor->i_length / 2;
if (i_services_number > DVBPSI_VBI_DR_MAX)
i_services_number = DVBPSI_VBI_DR_MAX;
/* Allocate memory */ /* Allocate memory */
p_decoded = (dvbpsi_vbi_dr_t*)malloc(sizeof(dvbpsi_vbi_dr_t)); p_decoded = (dvbpsi_vbi_dr_t*)malloc(sizeof(dvbpsi_vbi_dr_t));
...@@ -79,6 +81,8 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr( ...@@ -79,6 +81,8 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
p_decoded->p_services[i].i_data_service_id = i_data_service_id; p_decoded->p_services[i].i_data_service_id = i_data_service_id;
i_lines = ((uint8_t)(p_descriptor->p_data[3 * i + 3])); i_lines = ((uint8_t)(p_descriptor->p_data[3 * i + 3]));
if (i_lines > DVBPSI_VBIDATA_LINE_DR_MAX)
i_lines = DVBPSI_VBIDATA_LINE_DR_MAX;
p_decoded->p_services[i].i_lines = i_lines; p_decoded->p_services[i].i_lines = i_lines;
for (int n = 0; n < i_lines; n++ ) for (int n = 0; n < i_lines; n++ )
{ {
...@@ -103,6 +107,9 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr( ...@@ -103,6 +107,9 @@ dvbpsi_vbi_dr_t * dvbpsi_DecodeVBIDataDr(
dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(dvbpsi_vbi_dr_t * p_decoded, dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(dvbpsi_vbi_dr_t * p_decoded,
bool b_duplicate) bool b_duplicate)
{ {
if (p_decoded->i_services_number > DVBPSI_VBI_DR_MAX)
p_decoded->i_services_number = DVBPSI_VBI_DR_MAX;
/* Create the descriptor */ /* Create the descriptor */
dvbpsi_descriptor_t * p_descriptor = dvbpsi_descriptor_t * p_descriptor =
dvbpsi_NewDescriptor(0x45, p_decoded->i_services_number * 5 , NULL); dvbpsi_NewDescriptor(0x45, p_decoded->i_services_number * 5 , NULL);
...@@ -115,6 +122,9 @@ dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(dvbpsi_vbi_dr_t * p_decoded, ...@@ -115,6 +122,9 @@ dvbpsi_descriptor_t * dvbpsi_GenVBIDataDr(dvbpsi_vbi_dr_t * p_decoded,
p_descriptor->p_data[5 * i + 3] = p_descriptor->p_data[5 * i + 3] =
( (uint8_t) p_decoded->p_services[i].i_data_service_id ); ( (uint8_t) p_decoded->p_services[i].i_data_service_id );
if (p_decoded->p_services[i].i_lines > DVBPSI_VBIDATA_LINE_DR_MAX)
p_decoded->p_services[i].i_lines = DVBPSI_VBIDATA_LINE_DR_MAX;
p_descriptor->p_data[5 * i + 4] = p_decoded->p_services[i].i_lines; p_descriptor->p_data[5 * i + 4] = p_decoded->p_services[i].i_lines;
for (int n=0; n < p_decoded->p_services[i].i_lines; n++ ) for (int n=0; n < p_decoded->p_services[i].i_lines; n++ )
{ {
......
...@@ -60,6 +60,13 @@ typedef struct dvbpsi_vbidata_line_s ...@@ -60,6 +60,13 @@ typedef struct dvbpsi_vbidata_line_s
} dvbpsi_vbidata_line_t; } dvbpsi_vbidata_line_t;
/*!
* \def DVBPSI_VBIDATA_LINE_DR_MAX
* \brief Maximum number of dvbpsi_vbidata_line_t entries present in
* @see dvbpsi_vbidata_t
*/
#define DVBPSI_VBIDATA_LINE_DR_MAX 255
/***************************************************************************** /*****************************************************************************
* dvbpsi_vbidata_t * dvbpsi_vbidata_t
*****************************************************************************/ *****************************************************************************/
...@@ -82,6 +89,13 @@ typedef struct dvbpsi_vbidata_s ...@@ -82,6 +89,13 @@ typedef struct dvbpsi_vbidata_s
} dvbpsi_vbidata_t; } dvbpsi_vbidata_t;
/*!
* \def DVBPSI_VBI_DR_MAX
* \brief Maximum number of dvbpsi_vbidata_t entries present in
* @see dvbpsi_vbi_dr_t
*/
#define DVBPSI_VBI_DR_MAX 85
/***************************************************************************** /*****************************************************************************
* dvbpsi_vbi_dr_t * dvbpsi_vbi_dr_t
*****************************************************************************/ *****************************************************************************/
...@@ -99,7 +113,7 @@ typedef struct dvbpsi_vbidata_s ...@@ -99,7 +113,7 @@ typedef struct dvbpsi_vbidata_s
typedef struct dvbpsi_vbi_dr_s typedef struct dvbpsi_vbi_dr_s
{ {
uint8_t i_services_number; /*!< service number */ uint8_t i_services_number; /*!< service number */
dvbpsi_vbidata_t p_services[85]; /*!< services table */ dvbpsi_vbidata_t p_services[DVBPSI_VBI_DR_MAX]; /*!< services table */
} dvbpsi_vbi_dr_t; } dvbpsi_vbi_dr_t;
......
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