public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] ALSA: hda - potential (but unlikely) uninitialized variable
@ 2015-04-17 12:35 Dan Carpenter
  2015-04-17 12:42 ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2015-04-17 12:35 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: Takashi Iwai, David Henningsson, alsa-devel, kernel-janitors

This function is a bit unusual because it accepts negative values as
"conn_len".  It's theoretically possible for both "cache_len" and
"conn_len" to be -ENOSPC and in that case we would oops trying to run
memcmp() on the uninitialized "list" pointer.

My static checker complains about this.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index ce5a6da..387fdfc 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -556,8 +556,8 @@ static void print_conn_list(struct snd_info_buffer *buffer,
 
 	/* Get Cache connections info */
 	cache_len = snd_hda_get_conn_list(codec, nid, &list);
-	if (cache_len != conn_len
-			|| memcmp(list, conn, conn_len)) {
+	if (cache_len < 0 || cache_len != conn_len ||
+	    memcmp(list, conn, conn_len) != 0) {
 		snd_iprintf(buffer, "  In-driver Connection: %d\n", cache_len);
 		if (cache_len > 0) {
 			snd_iprintf(buffer, "    ");

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

* Re: [patch] ALSA: hda - potential (but unlikely) uninitialized variable
  2015-04-17 12:35 [patch] ALSA: hda - potential (but unlikely) uninitialized variable Dan Carpenter
@ 2015-04-17 12:42 ` Takashi Iwai
  2015-04-17 12:46   ` Dan Carpenter
  2015-04-17 13:19   ` [patch v2] " Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Takashi Iwai @ 2015-04-17 12:42 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, David Henningsson, alsa-devel, kernel-janitors

At Fri, 17 Apr 2015 15:35:15 +0300,
Dan Carpenter wrote:
> 
> This function is a bit unusual because it accepts negative values as
> "conn_len".  It's theoretically possible for both "cache_len" and
> "conn_len" to be -ENOSPC and in that case we would oops trying to run
> memcmp() on the uninitialized "list" pointer.

Yes, that's a bug.  But the check should be rather:

	if (cache_len >= 0 && (cache_len != conn_len ||
		    memcmp(list, conn, conn_len) != 0))

Could you resend with this fix?


thanks,

Takashi


> 
> My static checker complains about this.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
> index ce5a6da..387fdfc 100644
> --- a/sound/pci/hda/hda_proc.c
> +++ b/sound/pci/hda/hda_proc.c
> @@ -556,8 +556,8 @@ static void print_conn_list(struct snd_info_buffer *buffer,
>  
>  	/* Get Cache connections info */
>  	cache_len = snd_hda_get_conn_list(codec, nid, &list);
> -	if (cache_len != conn_len
> -			|| memcmp(list, conn, conn_len)) {
> +	if (cache_len < 0 || cache_len != conn_len ||
> +	    memcmp(list, conn, conn_len) != 0) {
>  		snd_iprintf(buffer, "  In-driver Connection: %d\n", cache_len);
>  		if (cache_len > 0) {
>  			snd_iprintf(buffer, "    ");
> 

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

* Re: [patch] ALSA: hda - potential (but unlikely) uninitialized variable
  2015-04-17 12:42 ` Takashi Iwai
@ 2015-04-17 12:46   ` Dan Carpenter
  2015-04-17 13:19   ` [patch v2] " Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2015-04-17 12:46 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, David Henningsson, alsa-devel, kernel-janitors

On Fri, Apr 17, 2015 at 02:42:05PM +0200, Takashi Iwai wrote:
> At Fri, 17 Apr 2015 15:35:15 +0300,
> Dan Carpenter wrote:
> > 
> > This function is a bit unusual because it accepts negative values as
> > "conn_len".  It's theoretically possible for both "cache_len" and
> > "conn_len" to be -ENOSPC and in that case we would oops trying to run
> > memcmp() on the uninitialized "list" pointer.
> 
> Yes, that's a bug.  But the check should be rather:
> 
> 	if (cache_len >= 0 && (cache_len != conn_len ||
> 		    memcmp(list, conn, conn_len) != 0))
> 
> Could you resend with this fix?

Sure.  Will do.

regards,
dan carpenter


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

* [patch v2] ALSA: hda - potential (but unlikely) uninitialized variable
  2015-04-17 12:42 ` Takashi Iwai
  2015-04-17 12:46   ` Dan Carpenter
@ 2015-04-17 13:19   ` Dan Carpenter
  2015-04-17 13:32     ` Takashi Iwai
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2015-04-17 13:19 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Takashi Iwai, alsa-devel, kernel-janitors

This function is a bit unusual because it accepts negative values as
"conn_len".  It's theoretically possible for both "cache_len" and
"conn_len" to be -ENOSPC and in that case we would oops trying to run
memcmp() on the uninitialized "list" pointer.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Don't print a negative error code as "In-driver Connection."

diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index ee62307..2f00886 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -582,8 +582,8 @@ static void print_conn_list(struct snd_info_buffer *buffer,
 
 	/* Get Cache connections info */
 	cache_len = snd_hda_get_conn_list(codec, nid, &list);
-	if (cache_len != conn_len
-			|| memcmp(list, conn, conn_len)) {
+	if (cache_len >= 0 && (cache_len != conn_len ||
+			      memcmp(list, conn, conn_len) != 0)) {
 		snd_iprintf(buffer, "  In-driver Connection: %d\n", cache_len);
 		if (cache_len > 0) {
 			snd_iprintf(buffer, "    ");

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

* Re: [patch v2] ALSA: hda - potential (but unlikely) uninitialized variable
  2015-04-17 13:19   ` [patch v2] " Dan Carpenter
@ 2015-04-17 13:32     ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2015-04-17 13:32 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: alsa-devel, kernel-janitors

At Fri, 17 Apr 2015 16:19:46 +0300,
Dan Carpenter wrote:
> 
> This function is a bit unusual because it accepts negative values as
> "conn_len".  It's theoretically possible for both "cache_len" and
> "conn_len" to be -ENOSPC and in that case we would oops trying to run
> memcmp() on the uninitialized "list" pointer.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Don't print a negative error code as "In-driver Connection."

Applied, thanks.


Takashi

> 
> diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
> index ee62307..2f00886 100644
> --- a/sound/pci/hda/hda_proc.c
> +++ b/sound/pci/hda/hda_proc.c
> @@ -582,8 +582,8 @@ static void print_conn_list(struct snd_info_buffer *buffer,
>  
>  	/* Get Cache connections info */
>  	cache_len = snd_hda_get_conn_list(codec, nid, &list);
> -	if (cache_len != conn_len
> -			|| memcmp(list, conn, conn_len)) {
> +	if (cache_len >= 0 && (cache_len != conn_len ||
> +			      memcmp(list, conn, conn_len) != 0)) {
>  		snd_iprintf(buffer, "  In-driver Connection: %d\n", cache_len);
>  		if (cache_len > 0) {
>  			snd_iprintf(buffer, "    ");
> 

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

end of thread, other threads:[~2015-04-17 13:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-17 12:35 [patch] ALSA: hda - potential (but unlikely) uninitialized variable Dan Carpenter
2015-04-17 12:42 ` Takashi Iwai
2015-04-17 12:46   ` Dan Carpenter
2015-04-17 13:19   ` [patch v2] " Dan Carpenter
2015-04-17 13:32     ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox