NetBSD Problem Report #47003

From www@NetBSD.org  Thu Sep 27 04:20:46 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 80BD963E47E
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 27 Sep 2012 04:20:46 +0000 (UTC)
Message-Id: <20120927042044.EB15863B9BC@www.NetBSD.org>
Date: Thu, 27 Sep 2012 04:20:44 +0000 (UTC)
From: isaki@pastel-flower.jp
Reply-To: isaki@pastel-flower.jp
To: gnats-bugs@NetBSD.org
Subject: mixerctl -a causes SEGV with no mixer environment on 6.0_RC2
X-Send-Pr-Version: www-1.0

>Number:         47003
>Category:       bin
>Synopsis:       mixerctl -a causes SEGV with no mixer environment on 6.0_RC2
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 27 04:25:00 +0000 2012
>Closed-Date:    Sun Oct 28 02:07:11 +0000 2012
>Last-Modified:  Sun Oct 28 02:07:11 +0000 2012
>Originator:     Tetsuya Isaki
>Release:        NetBSD/x68k-6.0_RC2
>Organization:
NetBSD
>Environment:
NetBSD XXXXXX 6.0_RC2 NetBSD 6.0_RC2 (GENERIC) #1: Sun Sep 16 14:30:42 JST 2012 isaki@XXXXXX:/var/obj/6/x68k/obj/sys/arch/x68k/compile/GENERIC x68k
>Description:
mixerctl -a causes SEGV, if there is audio device but no mixer
features (like x68k).

 # uname -srm
 NetBSD 6.0_RC2 x68k
 # dmesg | grep audio
 audio0 at vs0: half duplex, playback, capture
 # mixerctl -a
 Segmentation fault (core dumped)

x68k's vs(4) audio device does not support mixer features.
I think that it is a problem. But they are different problem
(i.e., the userland program should not SEGV regardless of a kenerl).


In this x68k's case, at main() in mixerctl.c line 375,
the first ioctl AUDIO_MIXER_DEVINFO failed. So ndev is 0.

  375     for(ndev = 0; ; ndev++) {
  376         dinfo.index = ndev;
  377         if (ioctl(fd, AUDIO_MIXER_DEVINFO, &dinfo) < 0)
  378             break;
  379     }

At line 381, fields = calloc(0).
calloc(0) returns non-NULL pointer with 0 bytes valid space.

  380     rfields = calloc(ndev, sizeof *rfields);
  381     fields = calloc(ndev, sizeof *fields);

And then, at line 432, accessing a member of fields[i] is invalid!
(SEGV really happened in prfield())

  431     if (argc == 0 && aflag && !wflag) {
  432         for(i = 0; fields[i].name; i++) {
  433             prfield(&fields[i], sep, vflag);
  434             fprintf(out, "\n");
  435         }

Therefore how about the following patch?
(here, j is number of fields[], i.e. j = 0)

After this patch, mixerctl -a works silently.

--- mixerctl.c	14 Jul 2009 21:02:24 -0000	1.24
+++ mixerctl.c	27 Sep 2012 03:01:47 -0000
@@ -429,7 +429,7 @@
 	}

 	if (argc == 0 && aflag && !wflag) {
-		for(i = 0; fields[i].name; i++) {
+		for(i = 0; i < j; i++) {
 			prfield(&fields[i], sep, vflag);
 			fprintf(out, "\n");
 		}

>How-To-Repeat:
mixerctl -a on x68k
>Fix:
See above.

>Release-Note:

>Audit-Trail:
From: "Tetsuya Isaki" <isaki@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47003 CVS commit: src/usr.bin/mixerctl
Date: Sun, 28 Oct 2012 01:51:20 +0000

 Module Name:	src
 Committed By:	isaki
 Date:		Sun Oct 28 01:51:20 UTC 2012

 Modified Files:
 	src/usr.bin/mixerctl: mixerctl.c

 Log Message:
 Avoid SEGV even if audio device has no mixer features.
 Fix PR/47003


 To generate a diff of this commit:
 cvs rdiff -u -r1.24 -r1.25 src/usr.bin/mixerctl/mixerctl.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: isaki@NetBSD.org
State-Changed-When: Sun, 28 Oct 2012 02:07:11 +0000
State-Changed-Why:
commited.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.