>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:
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to