From: Takashi Iwai Subject: Re: hdsp: potential oops in snd_hdsp_info_pref_sync_ref() Date: Mon, 09 Jan 2012 18:29:11 +0100 Message-ID: References: <20120106135957.GA4316@elgon.mountain> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id D7225103AB5 for ; Mon, 9 Jan 2012 18:29:13 +0100 (CET) In-Reply-To: <20120106135957.GA4316@elgon.mountain> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Dan Carpenter Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Fri, 6 Jan 2012 16:59:57 +0300, Dan Carpenter wrote: > > My static check complains that there is a potential oops here but I'm > not sure what the correct fix is. > > sound/pci/rme9652/hdsp.c > 2631 switch (hdsp->io_type) { > 2632 case Digiface: > 2633 case H9652: > 2634 uinfo->value.enumerated.items = 6; > 2635 break; > 2636 case Multiface: > 2637 uinfo->value.enumerated.items = 4; > 2638 break; > 2639 case H9632: > 2640 uinfo->value.enumerated.items = 3; > 2641 break; > 2642 default: > 2643 uinfo->value.enumerated.items = 0; > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > We set this to zero here. > > 2644 break; > 2645 } > 2646 > 2647 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > enumerated.item is unsigned int so it's always greater or equal to zero. > > 2648 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; > > We set it to UINT_MAX here. > > 2649 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > Reading UINT_MAX beyond the end of the array here will probably oops. > > 2650 return 0; > > There is a similar issue in snd_asihpi_cmode_info(). Right, this is an obvious bug. The driver should return an error immediately there. I fixed them in the sound git tree now. Thanks! Takashi