From gahr@FreeBSD.org  Fri Jun 27 20:20:36 2008
Return-Path: <gahr@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 778D71065677
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Jun 2008 20:20:36 +0000 (UTC)
	(envelope-from gahr@FreeBSD.org)
Received: from cpanel03.rubas-s03.net (cpanel03.rubas-s03.net [195.182.222.73])
	by mx1.freebsd.org (Postfix) with ESMTP id 1D8818FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Jun 2008 20:20:35 +0000 (UTC)
	(envelope-from gahr@FreeBSD.org)
Received: from [213.142.183.219] (helo=gahrtop.localhost)
	by cpanel03.rubas-s03.net with esmtpa (Exim 4.68)
	(envelope-from <gahr@FreeBSD.org>)
	id 1KCKQs-0000pI-SQ
	for FreeBSD-gnats-submit@freebsd.org; Fri, 27 Jun 2008 22:20:34 +0200
Received: from gahrtop.localhost (localhost [127.0.0.1])
	by gahrtop.localhost (Postfix) with ESMTP id 9025650840
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Jun 2008 22:20:28 +0200 (CEST)
Message-Id: <1214598028.21571@gahrtop.localhost>
Date: Fri, 27 Jun 2008 22:20:28 +0200
From: "Pietro Cerutti" <gahr@FreeBSD.org>
To: "FreeBSD gnats submit" <FreeBSD-gnats-submit@freebsd.org>
Subject: [patch] cdcontrol enhancements to volume operations
X-Send-Pr-Version: gtk-send-pr 0.4.9 
X-GNATS-Notify:

>Number:         125054
>Category:       bin
>Synopsis:       [patch] cdcontrol(1): cdcontrol enhancements to volume operations
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gahr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 27 20:30:01 UTC 2008
>Closed-Date:    Fri Sep 05 14:11:12 UTC 2008
>Last-Modified:  Fri Sep 05 14:11:12 UTC 2008
>Originator:     Pietro Cerutti
>Release:        FreeBSD 8.0-CURRENT i386
>Organization:
The FreeBSD Project 
>Environment:


System: FreeBSD 8.0-CURRENT #2: Tue Jun 24 08:15:41 CEST 2008
    root@gahrtop.localhost:/usr/obj/usr/src/sys/MSI1034



>Description:


This includes the patches from bin/15480 and also fixes the case when volume values < 0 or > 255 are given on the command line.

Currently, now no sanity check is made on the values and the unsigned char storing the volume values either overflows or underflows if the given values are not in range.

E.g., 256 overflows to 0, -10 underflows to 246, ...

The patch reduces values <0 to 0 and values > 255 to 255.


>How-To-Repeat:





>Fix:


--- cdcontrol.diff begins here ---
Index: cdcontrol.1
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cdcontrol/cdcontrol.1,v
retrieving revision 1.40
diff -u -u -r1.40 cdcontrol.1
--- cdcontrol.1	18 Jan 2005 20:02:32 -0000	1.40
+++ cdcontrol.1	27 Jun 2008 20:14:00 -0000
@@ -1,6 +1,6 @@
 .\" $FreeBSD: src/usr.sbin/cdcontrol/cdcontrol.1,v 1.40 2005/01/18 20:02:32 ru Exp $
 .\"
-.Dd May 8, 2002
+.Dd June 27, 2008
 .Dt CDCONTROL 1
 .Os
 .Sh NAME
@@ -130,6 +130,14 @@
 Eject the disc.
 .It Ic close
 Inject the disc.
+.It Ic volume
+Same as 
+.Em status volume
+command.
+.It Ic volume Ar level
+Set the volume of both channels to
+.Ar level .
+Allowed values are in the range 0-255.
 .It Ic volume Ar left_channel right_channel
 Set the volume of left channel to
 .Ar left_channel
Index: cdcontrol.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cdcontrol/cdcontrol.c,v
retrieving revision 1.50
diff -u -u -r1.50 cdcontrol.c
--- cdcontrol.c	19 Feb 2008 07:09:18 -0000	1.50
+++ cdcontrol.c	27 Jun 2008 20:19:13 -0000
@@ -16,6 +16,19 @@
  * 11-Oct-1995: Serge V.Vakulenko <vak@cronyx.ru>
  *              New eject algorithm.
  *              Some code style reformatting.
+ * 
+ * 13-Dec-1999: Knut A. Syed <kas@kas.no>
+ * 		Volume-command modified.  If used with only one
+ * 		parameter it now sets both channels.  If used without
+ * 		parameters it will print volume-info.
+ * 		Version 2.0.1
+ *
+ * 27-Jun-2008  Pietro Cerutti <gahr@FreeBSD.org>
+ * 		Further enhancement to volume. Values not in range 0-255
+ * 		are now reduced to be in range. This prevents overflow in
+ * 		the uchar storing the volume (256 -> 0, -20 -> 236, ...).
+ * 		Version 2.0.2
+ *
  */
 
 #include <sys/cdefs.h>
@@ -39,7 +52,7 @@
 #include <unistd.h>
 #include <vis.h>
 
-#define VERSION "2.0"
+#define VERSION "2.0.2"
 
 #define ASTS_INVALID	0x00  /* Audio status byte not valid */
 #define ASTS_PLAYING	0x11  /* Audio play operation in progress */
@@ -100,7 +113,7 @@
 { CMD_STATUS,	"status",	1, "[audio | media | volume]" },
 { CMD_STOP,	"stop",		3, "" },
 { CMD_VOLUME,	"volume",	1,
-      "<l> <r> | left | right | mute | mono | stereo" },
+      "<l&r> <l> <r> | left | right | mute | mono | stereo" },
 { CMD_CDID,	"cdid",		2, "" },
 { CMD_SPEED,	"speed",	2, "speed" },
 { 0,		NULL,		0, NULL }
@@ -270,7 +283,7 @@
 int run (int cmd, char *arg)
 {
 	long speed;
-	int l, r, rc;
+	int l, r, rc, count;
 
 	switch (cmd) {
 
@@ -396,6 +409,9 @@
 		if (fd < 0 && !open_cd ())
 			return (0);
 
+		if (! strlen (arg))
+		    	return pstatus ("volume");
+
 		if (! strncasecmp (arg, "left", strlen(arg)))
 			return ioctl (fd, CDIOCSETLEFT);
 
@@ -411,12 +427,13 @@
 		if (! strncasecmp (arg, "mute", strlen(arg)))
 			return ioctl (fd, CDIOCSETMUTE);
 
-		if (2 != sscanf (arg, "%d %d", &l, &r)) {
-			warnx("invalid command arguments");
-			return (0);
-		}
-
-		return setvol (l, r);
+		count = sscanf (arg, "%d %d", &l, &r);
+		if (count == 1)
+		    return setvol (l, l);
+		if (count == 2)
+		    return setvol (l, r);
+		warnx("invalid command arguments");
+		return (0);
 
 	case CMD_SPEED:
 		if (fd < 0 && ! open_cd ())
@@ -1039,6 +1056,9 @@
 {
 	struct ioc_vol  v;
 
+	left  = left  < 0 ? 0 : left  > 255 ? 255 : left;
+	right = right < 0 ? 0 : right > 255 ? 255 : right;
+
 	v.vol[0] = left;
 	v.vol[1] = right;
 	v.vol[2] = 0;
--- cdcontrol.diff ends here ---



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: gahr 
State-Changed-When: Mon Jul 14 13:22:30 UTC 2008 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125054 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125054: commit references a PR
Date: Mon, 14 Jul 2008 13:22:39 +0000 (UTC)

 gahr        2008-07-14 13:22:09 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/cdcontrol   cdcontrol.1 cdcontrol.c 
   Log:
   SVN rev 180507 on 2008-07-14 13:22:09Z by gahr
   
   - Enhance volume handling
   
   PR:             125054
   Submitted by:   gahr
   Approved by:    cperciva
   
   Revision  Changes    Path
   1.41      +9 -1      src/usr.sbin/cdcontrol/cdcontrol.1
   1.51      +29 -9     src/usr.sbin/cdcontrol/cdcontrol.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: closed->patched 
State-Changed-By: gahr 
State-Changed-When: Mon Jul 14 14:04:23 UTC 2008 
State-Changed-Why:  
- Patch until MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125054 
Responsible-Changed-From-To: freebsd-bugs->gahr 
Responsible-Changed-By: gahr 
Responsible-Changed-When: Mon Jul 14 15:56:54 UTC 2008 
Responsible-Changed-Why:  
It's mine. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125054 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125054: commit references a PR
Date: Fri,  5 Sep 2008 14:08:42 +0000 (UTC)

 flz         2008-09-05 14:08:26 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     usr.sbin/cdcontrol   cdcontrol.1 cdcontrol.c 
   Log:
   SVN rev 182788 on 2008-09-05 14:08:26Z by flz
   
   MFC r180507: enhance volume handling.
   
   PR:             bin/125054
   Submitted by:   gahr
   Approved by:    re (gnn)
   
   Revision   Changes    Path
   1.40.10.1  +9 -1      src/usr.sbin/cdcontrol/cdcontrol.1
   1.49.2.1   +29 -9     src/usr.sbin/cdcontrol/cdcontrol.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125054: commit references a PR
Date: Fri,  5 Sep 2008 14:08:52 +0000 (UTC)

 flz         2008-09-05 14:08:42 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.sbin/cdcontrol   cdcontrol.1 cdcontrol.c 
   Log:
   SVN rev 182789 on 2008-09-05 14:08:42Z by flz
   
   MFC r180507: enhance volume handling.
   
   PR:             bin/125054
   Submitted by:   gahr
   Approved by:    re (gnn)
   
   Revision  Changes    Path
   1.40.2.1  +9 -1      src/usr.sbin/cdcontrol/cdcontrol.1
   1.48.8.1  +29 -9     src/usr.sbin/cdcontrol/cdcontrol.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: gahr 
State-Changed-When: Fri Sep 5 14:10:53 UTC 2008 
State-Changed-Why:  
MFC'd by:       flz (tnx!) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125054 
>Unformatted:
