All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <m.chehab@samsung.com>
To: "André Roth" <neolynx@gmail.com>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH 01/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private
Date: Tue, 07 Jan 2014 14:15:03 -0200	[thread overview]
Message-ID: <20140107141503.0106f396@samsung.com> (raw)
In-Reply-To: <1388855282-19295-1-git-send-email-neolynx@gmail.com>

Em Sat,  4 Jan 2014 18:07:51 +0100
André Roth <neolynx@gmail.com> escreveu:

description?

what are you fixing? why? how?


> Signed-off-by: André Roth <neolynx@gmail.com>
> ---
>  lib/include/libdvbv5/descriptors.h |    2 --
>  lib/libdvbv5/descriptors.c         |   44 ++++++++++++++++++------------------
>  2 files changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/lib/include/libdvbv5/descriptors.h b/lib/include/libdvbv5/descriptors.h
> index 6f89aeb..36bcc61 100644
> --- a/lib/include/libdvbv5/descriptors.h
> +++ b/lib/include/libdvbv5/descriptors.h
> @@ -78,8 +78,6 @@ void dvb_desc_default_print  (struct dvb_v5_fe_parms *parms, const struct dvb_de
>  	for( _struct *_desc = (_struct *) _tbl->descriptor; _desc; _desc = (_struct *) _desc->next ) \
>  		if(_desc->type == _type) \
>  
> -ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc);
> -
>  uint32_t bcd(uint32_t bcd);
>  
>  void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned char *buf, int len);
> diff --git a/lib/libdvbv5/descriptors.c b/lib/libdvbv5/descriptors.c
> index a2176b4..626f81d 100644
> --- a/lib/libdvbv5/descriptors.c
> +++ b/lib/libdvbv5/descriptors.c
> @@ -56,12 +56,11 @@
>  #include <libdvbv5/desc_partial_reception.h>
>  #include <libdvbv5/desc_extension.h>
>  
> -ssize_t dvb_desc_init(const uint8_t *buf, struct dvb_desc *desc)
> +static void dvb_desc_init(uint8_t type, uint8_t length, struct dvb_desc *desc)
>  {
> -	desc->type   = buf[0];
> -	desc->length = buf[1];
> +	desc->type   = type;
> +	desc->length = length;
>  	desc->next   = NULL;
> -	return 2;
>  }
>  
>  void dvb_desc_default_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
> @@ -94,16 +93,27 @@ char *default_charset = "iso-8859-1";
>  char *output_charset = "utf-8";
>  
>  void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
> -			   uint16_t section_length, struct dvb_desc **head_desc)
> +			   uint16_t buflen, struct dvb_desc **head_desc)
>  {
> -	const uint8_t *ptr = buf;
> +	const uint8_t *ptr = buf, *endbuf = buf + buflen;
>  	struct dvb_desc *current = NULL;
>  	struct dvb_desc *last = NULL;
> -	while (ptr < buf + section_length) {
> -		unsigned desc_type = ptr[0];
> -		int desc_len  = ptr[1];
> +
> +	*head_desc = NULL;
> +
> +	while (ptr + 2 <= endbuf ) {

No spaces before ')'

> +		uint8_t desc_type = ptr[0];
> +		uint8_t desc_len  = ptr[1];
>  		size_t size;
>  
> +		ptr += 2; /* skip type and length */
> +
> +		if (ptr + desc_len > endbuf) {
> +			dvb_logerr("short read of %zd/%d bytes parsing descriptor %#02x",
> +				   endbuf - ptr, desc_len, desc_type);
> +			return;
> +		}
> +
>  		switch (parms->verbose) {
>  		case 0:
>  		case 1:
> @@ -119,11 +129,6 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
>  			hexdump(parms, "content: ", ptr + 2, desc_len);
>  		}
>  
> -		if (desc_len > section_length - 2) {
> -			dvb_logwarn("descriptor type %0x02x is too big",
> -				   desc_type);
> -			return;
> -		}
>  
>  		dvb_desc_init_func init = dvb_descriptors[desc_type].init;
>  		if (!init) {
> @@ -133,21 +138,16 @@ void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
>  			size = dvb_descriptors[desc_type].size;
>  		}
>  		if (!size) {
> -			dvb_logwarn("descriptor type 0x%02x has no size defined", desc_type);
> -			size = 4096;
> -		}
> -		if (ptr + 2 >=  buf + section_length) {
> -			dvb_logwarn("descriptor type 0x%02x is truncated: desc len %d, section len %zd",
> -				   desc_type, desc_len, section_length - (ptr - buf));
> +			dvb_logerr("descriptor type 0x%02x has no size defined", desc_type);
>  			return;
>  		}
>  
> -		current = calloc(1, size);
> +		current = malloc(size);

Please either keep using calloc, or do a memset() to cleanup the newest
buffer. It is a bad idea to let the new buffers uninitialized.

>  		if (!current) {
>  			dvb_perror("Out of memory");
>  			return;
>  		}
> -		ptr += dvb_desc_init(ptr, current); /* the standard header was read */
> +		dvb_desc_init(desc_type, desc_len, current); /* initialize the standard header */
>  		init(parms, ptr, current);
>  		if (!*head_desc)
>  			*head_desc = current;


Btw, I saw some cleanups, but I didn't find any bug to be fixed on the
above.

Also, it is introducing a regression, when it replaced calloc() with
malloc().

Regard
-- 

Cheers,
Mauro

      parent reply	other threads:[~2014-01-07 16:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 17:07 [PATCH 01/11] libdvbv5: fix dvb_parse_descriptors and make dvb_desc_init private André Roth
2014-01-04 17:07 ` [PATCH 02/11] libdvbv5: add attribute packed to structs and unions André Roth
2014-01-04 17:07 ` [PATCH 03/11] libdvbv5: add parser for CAT André Roth
2014-01-04 17:07 ` [PATCH 04/11] libdvbv5: add parser for ca and ca_identifier descriptors André Roth
2014-01-04 17:07 ` [PATCH 05/11] libdvbv5: fix PMT parser André Roth
2014-01-04 17:07 ` [PATCH 06/11] libdvbv5: cleanup printing tables and descriptors André Roth
2014-01-04 17:07 ` [PATCH 07/11] libdvbv5: use DVB_DESC_HEADER macro in all descriptors André Roth
2014-01-04 17:07 ` [PATCH 08/11] libdvbv5: make dvb_desc_default_init and dvb_desc_default_print private André Roth
2014-01-04 17:07 ` [PATCH 09/11] libdvbv5: use TABLE_INIT macro André Roth
2014-01-04 17:08 ` [PATCH 10/11] libdvbv5: descriptor parser return int André Roth
2014-01-04 17:08 ` [PATCH 11/11] libdvbv5: remove unneeded includes André Roth
2014-01-07 16:15 ` Mauro Carvalho Chehab [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140107141503.0106f396@samsung.com \
    --to=m.chehab@samsung.com \
    --cc=linux-media@vger.kernel.org \
    --cc=neolynx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.