[alsa-devel] [PATCH] hda: add bounds checking for the codec command fields v2

Takashi Iwai tiwai at suse.de
Fri Jul 17 12:53:24 CEST 2009


At Fri, 17 Jul 2009 12:46:01 +0200,
I wrote:
> 
> At Fri, 17 Jul 2009 18:41:05 +0800,
> Guo, Chaohong wrote:
> > 
> > Although it does address this issue, I am not comfortable with this fixing. 
> > It seems more like a workaround than fix.
> 
> No, it's rather for catching a bug.  This is definitely neither
> "workaround" nor "fix".

BTW, I fixed the patch again as below.


Takashi

---
From 82e1b804b03defe46fb69ffd2c8b19e6649bcb0d Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai at suse.de>
Date: Fri, 17 Jul 2009 12:47:34 +0200
Subject: [PATCH] ALSA: hda - Fix the previous sanity check in make_codec_cmd()

The newly added sanity-check for a codec verb can be better written
with logical ORs.  Also, the parameter can be more than 8bit.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 sound/pci/hda/hda_codec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index d9d3262..35f0f22 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -150,8 +150,8 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
 {
 	u32 val;
 
-	if ((codec->addr & ~0xf) | (direct & ~1) | (nid & ~0x7f) |
-	    (verb & ~0xfff) | (parm & ~0xff)) {
+	if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) ||
+	    (verb & ~0xfff) || (parm & ~0xffff)) {
 		printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n",
 		       codec->addr, direct, nid, verb, parm);
 		return ~0;
-- 
1.6.3.2



More information about the Alsa-devel mailing list