Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Nov 2012 03:58:28 GMT
From:      Garrett Cooper <yanegomi@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/173923: [patch] save errno before calling fprintf in cpucontrol(8) error paths
Message-ID:  <201211260358.qAQ3wSCp033956@red.freebsd.org>
Resent-Message-ID: <201211260400.qAQ40018092344@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         173923
>Category:       bin
>Synopsis:       [patch] save errno before calling fprintf in cpucontrol(8) error paths
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 26 04:00:00 UTC 2012
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211260358.qAQ3wSCp033956>