From nobody@FreeBSD.org  Mon Nov 26 03:58:28 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 59ABD982
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 26 Nov 2012 03:58:28 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 4185F8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 26 Nov 2012 03:58:28 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qAQ3wSIT033957
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 26 Nov 2012 03:58:28 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qAQ3wSCp033956;
	Mon, 26 Nov 2012 03:58:28 GMT
	(envelope-from nobody)
Message-Id: <201211260358.qAQ3wSCp033956@red.freebsd.org>
Date: Mon, 26 Nov 2012 03:58:28 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] save errno before calling fprintf in cpucontrol(8) error paths
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173923
>Category:       bin
>Synopsis:       [patch] save errno before calling fprintf in cpucontrol(8) error paths
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 26 04:00:00 UTC 2012
>Closed-Date:    Sun Feb 03 03:46:15 UTC 2013
>Last-Modified:  Sun Feb 03 22:31:25 UTC 2013
>Originator:     Garrett Cooper
>Release:        9-STABLE
>Organization:
EMC Isilon
>Environment:
FreeBSD bayonetta.local 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r240836M: Sat Sep 22 12:30:11 PDT 2012     gcooper@bayonetta.local:/usr/obj/store/freebsd/stable/9/sys/BAYONETTA  amd64
>Description:
fprintf can mangle errno, tainting WARN calls. The attached patch saves errno in error (which was used to store the return code from the ioctl(2) calls) and restores it after calling WARN.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: usr.sbin/cpucontrol/intel.c
===================================================================
--- usr.sbin/cpucontrol/intel.c	(revision 242874)
+++ usr.sbin/cpucontrol/intel.c	(working copy)
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
+#include <errno.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -266,7 +267,9 @@
 	args.size = data_size;
 	error = ioctl(devfd, CPUCTL_UPDATE, &args);
 	if (error < 0) {
+		error = errno;
 		fprintf(stderr, "failed.\n");
+		errno = error;
 		WARN(0, "ioctl()");
 		goto fail;
 	}
Index: usr.sbin/cpucontrol/via.c
===================================================================
--- usr.sbin/cpucontrol/via.c	(revision 242874)
+++ usr.sbin/cpucontrol/via.c	(working copy)
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
+#include <errno.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -204,7 +205,9 @@
 	args.size = data_size;
 	error = ioctl(devfd, CPUCTL_UPDATE, &args);
 	if (error < 0) {
+		error = errno;
 		fprintf(stderr, "failed.\n");
+		errno = error;
 		WARN(0, "ioctl()");
 		goto fail;
 	}


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Dec 20 17:55:46 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

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

From: Eitan Adler <lists@eitanadler.com>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/173923: [patch] save errno before calling fprintf in
 cpucontrol(8) error paths
Date: Thu, 20 Dec 2012 13:03:32 -0500

 On 25 November 2012 22:58, Garrett Cooper <yaneurabeya@gmail.com> wrote:
 >>Description:
 > fprintf can mangle errno, tainting WARN calls. The attached patch saves errno in error (which was used to store the return code from the ioctl(2) calls) and restores
 it after calling WARN.
 
 Did you mean to restore it *before* calling warn, or after?
 
 [ignore this: commit 68f39bd663d3ab6c1f31767e40a71ebf10e4b703]
 -- 
 Eitan Adler

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Eitan Adler <lists@eitanadler.com>
Cc: "freebsd-gnats-submit@freebsd.org" <freebsd-gnats-submit@freebsd.org>
Subject: Re: bin/173923: [patch] save errno before calling fprintf in cpucontrol(8) error paths
Date: Thu, 20 Dec 2012 10:24:14 -0800

 Save before, restore after
 
 Sent from my iPhone
 
 On Dec 20, 2012, at 10:03 AM, Eitan Adler <lists@eitanadler.com> wrote:
 
 > On 25 November 2012 22:58, Garrett Cooper <yaneurabeya@gmail.com> wrote:
 >>> Description:
 >> fprintf can mangle errno, tainting WARN calls. The attached patch saves e=
 rrno in error (which was used to store the return code from the ioctl(2) cal=
 ls) and restores
 > it after calling WARN.
 >=20
 > Did you mean to restore it *before* calling warn, or after?
 >=20
 > [ignore this: commit 68f39bd663d3ab6c1f31767e40a71ebf10e4b703]
 > --=20
 > Eitan Adler
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Fri Dec 21 07:33:57 UTC 2012 
State-Changed-Why:  
awaiting approval or review prior to commit (no action needed from 
submitter) 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/173923: commit references a PR
Date: Wed, 16 Jan 2013 05:00:59 +0000 (UTC)

 Author: eadler
 Date: Wed Jan 16 05:00:51 2013
 New Revision: 245491
 URL: http://svnweb.freebsd.org/changeset/base/245491
 
 Log:
   Avoid clobbering errno with a call to fprintf
   
   PR:		bin/173923
   Submitted by:	Garrett Cooper <yaneurabeya@gmail.com>
   Approved by:	cperciva
   MFC After:	3 days
 
 Modified:
   head/usr.sbin/cpucontrol/intel.c
   head/usr.sbin/cpucontrol/via.c
 
 Modified: head/usr.sbin/cpucontrol/intel.c
 ==============================================================================
 --- head/usr.sbin/cpucontrol/intel.c	Wed Jan 16 04:45:45 2013	(r245490)
 +++ head/usr.sbin/cpucontrol/intel.c	Wed Jan 16 05:00:51 2013	(r245491)
 @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
  #include <unistd.h>
  #include <fcntl.h>
  #include <err.h>
 +#include <errno.h>
  
  #include <sys/types.h>
  #include <sys/stat.h>
 @@ -266,7 +267,9 @@ matched:
  	args.size = data_size;
  	error = ioctl(devfd, CPUCTL_UPDATE, &args);
  	if (error < 0) {
 +               error = errno;
  		fprintf(stderr, "failed.\n");
 +               errno = error;
  		WARN(0, "ioctl()");
  		goto fail;
  	}
 
 Modified: head/usr.sbin/cpucontrol/via.c
 ==============================================================================
 --- head/usr.sbin/cpucontrol/via.c	Wed Jan 16 04:45:45 2013	(r245490)
 +++ head/usr.sbin/cpucontrol/via.c	Wed Jan 16 05:00:51 2013	(r245491)
 @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
  #include <unistd.h>
  #include <fcntl.h>
  #include <err.h>
 +#include <errno.h>
  
  #include <sys/types.h>
  #include <sys/stat.h>
 @@ -203,7 +204,9 @@ via_update(const char *dev, const char *
  	args.size = data_size;
  	error = ioctl(devfd, CPUCTL_UPDATE, &args);
  	if (error < 0) {
 +               error = errno;
  		fprintf(stderr, "failed.\n");
 +               errno = error;
  		WARN(0, "ioctl()");
  		goto fail;
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: eadler 
State-Changed-When: Sun Feb 3 03:46:14 UTC 2013 
State-Changed-Why:  
Committed. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/173923: commit references a PR
Date: Sun,  3 Feb 2013 03:46:28 +0000 (UTC)

 Author: eadler
 Date: Sun Feb  3 03:46:16 2013
 New Revision: 246281
 URL: http://svnweb.freebsd.org/changeset/base/246281
 
 Log:
   MFC r245491:
   	Avoid clobbering errno with a call to fprintf
   
   PR:		bin/173923
   Approved by:	cperciva (mentor, implicit)
 
 Modified:
   stable/9/usr.sbin/cpucontrol/intel.c
   stable/9/usr.sbin/cpucontrol/via.c
 Directory Properties:
   stable/9/usr.sbin/cpucontrol/   (props changed)
 
 Modified: stable/9/usr.sbin/cpucontrol/intel.c
 ==============================================================================
 --- stable/9/usr.sbin/cpucontrol/intel.c	Sun Feb  3 03:43:59 2013	(r246280)
 +++ stable/9/usr.sbin/cpucontrol/intel.c	Sun Feb  3 03:46:16 2013	(r246281)
 @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
  #include <unistd.h>
  #include <fcntl.h>
  #include <err.h>
 +#include <errno.h>
  
  #include <sys/types.h>
  #include <sys/stat.h>
 @@ -266,7 +267,9 @@ matched:
  	args.size = data_size;
  	error = ioctl(devfd, CPUCTL_UPDATE, &args);
  	if (error < 0) {
 +               error = errno;
  		fprintf(stderr, "failed.\n");
 +               errno = error;
  		WARN(0, "ioctl()");
  		goto fail;
  	}
 
 Modified: stable/9/usr.sbin/cpucontrol/via.c
 ==============================================================================
 --- stable/9/usr.sbin/cpucontrol/via.c	Sun Feb  3 03:43:59 2013	(r246280)
 +++ stable/9/usr.sbin/cpucontrol/via.c	Sun Feb  3 03:46:16 2013	(r246281)
 @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
  #include <unistd.h>
  #include <fcntl.h>
  #include <err.h>
 +#include <errno.h>
  
  #include <sys/types.h>
  #include <sys/stat.h>
 @@ -204,7 +205,9 @@ via_update(const char *dev, const char *
  	args.size = data_size;
  	error = ioctl(devfd, CPUCTL_UPDATE, &args);
  	if (error < 0) {
 +               error = errno;
  		fprintf(stderr, "failed.\n");
 +               errno = error;
  		WARN(0, "ioctl()");
  		goto fail;
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
