linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next][V2] media: allegro: fix potential null dereference on header
@ 2020-07-22 13:09 Colin King
  2020-07-22 13:16 ` Michael Tretter
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-07-22 13:09 UTC (permalink / raw)
  To: Michael Tretter, Pengutronix Kernel Team, Mauro Carvalho Chehab,
	Hans Verkuil, linux-media, devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The pointer header is an alias to msg and msg is being null checked.
However, if msg is null then header is also null and this can lead to
a null pointer dereference on the assignment type = header->type. Fix
this just using header->type after the null check and removing the need
for type as it is only used once.

Addresses-Coverity: ("Dereference before null check")
Fixes: 3de16839669f ("media: allegro: add explicit mail encoding and decoding")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: remove need for variable type, as suggested by Michael Tretter

---
 drivers/staging/media/allegro-dvt/allegro-mail.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/media/allegro-dvt/allegro-mail.c b/drivers/staging/media/allegro-dvt/allegro-mail.c
index 4ac65de12463..9286d2162377 100644
--- a/drivers/staging/media/allegro-dvt/allegro-mail.c
+++ b/drivers/staging/media/allegro-dvt/allegro-mail.c
@@ -462,13 +462,12 @@ allegro_dec_encode_frame(struct mcu_msg_encode_frame_response *msg, u32 *src)
 ssize_t allegro_encode_mail(u32 *dst, void *msg)
 {
 	const struct mcu_msg_header *header = msg;
-	enum mcu_msg_type type = header->type;
 	ssize_t size;
 
 	if (!msg || !dst)
 		return -EINVAL;
 
-	switch (type) {
+	switch (header->type) {
 	case MCU_MSG_TYPE_INIT:
 		size = allegro_enc_init(&dst[1], msg);
 		break;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next][V2] media: allegro: fix potential null dereference on header
  2020-07-22 13:09 [PATCH][next][V2] media: allegro: fix potential null dereference on header Colin King
@ 2020-07-22 13:16 ` Michael Tretter
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Tretter @ 2020-07-22 13:16 UTC (permalink / raw)
  To: Colin King
  Cc: Pengutronix Kernel Team, Mauro Carvalho Chehab, Hans Verkuil,
	linux-media, devel, kernel-janitors, linux-kernel

On Wed, 22 Jul 2020 14:09:03 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer header is an alias to msg and msg is being null checked.
> However, if msg is null then header is also null and this can lead to
> a null pointer dereference on the assignment type = header->type. Fix
> this just using header->type after the null check and removing the need
> for type as it is only used once.
> 
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 3de16839669f ("media: allegro: add explicit mail encoding and decoding")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Michael Tretter <m.tretter@pengutronix.de>

> ---
> 
> V2: remove need for variable type, as suggested by Michael Tretter
> 
> ---
>  drivers/staging/media/allegro-dvt/allegro-mail.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/allegro-dvt/allegro-mail.c b/drivers/staging/media/allegro-dvt/allegro-mail.c
> index 4ac65de12463..9286d2162377 100644
> --- a/drivers/staging/media/allegro-dvt/allegro-mail.c
> +++ b/drivers/staging/media/allegro-dvt/allegro-mail.c
> @@ -462,13 +462,12 @@ allegro_dec_encode_frame(struct mcu_msg_encode_frame_response *msg, u32 *src)
>  ssize_t allegro_encode_mail(u32 *dst, void *msg)
>  {
>  	const struct mcu_msg_header *header = msg;
> -	enum mcu_msg_type type = header->type;
>  	ssize_t size;
>  
>  	if (!msg || !dst)
>  		return -EINVAL;
>  
> -	switch (type) {
> +	switch (header->type) {
>  	case MCU_MSG_TYPE_INIT:
>  		size = allegro_enc_init(&dst[1], msg);
>  		break;
> -- 
> 2.27.0
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-22 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 13:09 [PATCH][next][V2] media: allegro: fix potential null dereference on header Colin King
2020-07-22 13:16 ` Michael Tretter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).