NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/47003: mixerctl -a causes SEGV with no mixer environment on 6.0_RC2



>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:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 27 04:25:00 +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.



Home | Main Index | Thread Index | Old Index