From owner-freebsd-bugs@FreeBSD.ORG Mon Nov 26 04:00:01 2012 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 00F85994 for ; Mon, 26 Nov 2012 04:00:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id CA7938FC14 for ; Mon, 26 Nov 2012 04:00:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qAQ4002d092345 for ; Mon, 26 Nov 2012 04:00:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qAQ40018092344; Mon, 26 Nov 2012 04:00:00 GMT (envelope-from gnats) Resent-Date: Mon, 26 Nov 2012 04:00:00 GMT Resent-Message-Id: <201211260400.qAQ40018092344@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 59ABD982 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: bin/173923: [patch] save errno before calling fprintf in cpucontrol(8) error paths X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Nov 2012 04:00:01 -0000 >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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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: