From nobody@FreeBSD.org  Sat Sep  5 20:50:25 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id EB427106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  5 Sep 2009 20:50:25 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id DA9748FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  5 Sep 2009 20:50:25 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n85KoPfa080126
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 5 Sep 2009 20:50:25 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n85KoP4X080125;
	Sat, 5 Sep 2009 20:50:25 GMT
	(envelope-from nobody)
Message-Id: <200909052050.n85KoP4X080125@www.freebsd.org>
Date: Sat, 5 Sep 2009 20:50:25 GMT
From: Bruce Cran <bruce@cran.org.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] fix truncated witness sysctl string due to incorrect use of sizeof
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138557
>Category:       kern
>Synopsis:       [patch] fix truncated witness sysctl string due to incorrect use of sizeof
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    antoine
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 05 21:00:13 UTC 2009
>Closed-Date:    Sat Oct 31 12:33:01 UTC 2009
>Last-Modified:  Sat Oct 31 12:33:01 UTC 2009
>Originator:     Bruce Cran
>Release:        8.0-BETA3
>Organization:
>Environment:
FreeBSD gluon.draftnet 8.0-BETA3 FreeBSD 8.0-BETA3 #1: Fri Sep  4 09:20:32 BST 2009     brucec@gluon.draftnet:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
In sys/kern/subr_witness.c the strings "Witness not running" and "Witness is still cold" get truncated to "Witn" in the sysctl tree because sizeof is used instead of strlen. 
>How-To-Repeat:
sysctl debug.witness.watch=0
sysctl debug.witness.badstacks

>Fix:


Patch attached with submission follows:

--- subr_witness.c.orig	2009-09-05 21:24:40.000000000 +0100
+++ subr_witness.c	2009-09-05 21:25:42.000000000 +0100
@@ -2378,11 +2378,11 @@
 	tmp_w1 = NULL;
 	tmp_w2 = NULL;
 	if (witness_watch < 1) {
-		error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning));
+		error = SYSCTL_OUT(req, w_notrunning, strlen(w_notrunning) + 1);
 		return (error);
 	}
 	if (witness_cold) {
-		error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold));
+		error = SYSCTL_OUT(req, w_stillcold, strlen(w_stillcold) + 1);
 		return (error);
 	}
 	error = 0;
@@ -2530,11 +2530,11 @@
 	int error;
 
 	if (witness_watch < 1) {
-		error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning));
+		error = SYSCTL_OUT(req, w_notrunning, strlen(w_notrunning) + 1);
 		return (error);
 	}
 	if (witness_cold) {
-		error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold));
+		error = SYSCTL_OUT(req, w_stillcold, strlen(w_stillcold) + 1);
 		return (error);
 	}
 	error = 0;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->antoine 
Responsible-Changed-By: antoine 
Responsible-Changed-When: Sun Sep 6 12:48:52 UTC 2009 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138557 
State-Changed-From-To: open->patched 
State-Changed-By: antoine 
State-Changed-When: Sun Sep 6 13:36:03 UTC 2009 
State-Changed-Why:  
Fixed in head. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/138557: commit references a PR
Date: Sun,  6 Sep 2009 13:31:19 +0000 (UTC)

 Author: antoine
 Date: Sun Sep  6 13:31:05 2009
 New Revision: 196891
 URL: http://svn.freebsd.org/changeset/base/196891
 
 Log:
   Change w_notrunning and w_stillcold from pointer to array so that sizeof
   returns what is expected.
   
   PR:		kern/138557
   Discussed with:	brucec@
   MFC after:	1 month
 
 Modified:
   head/sys/kern/subr_witness.c
 
 Modified: head/sys/kern/subr_witness.c
 ==============================================================================
 --- head/sys/kern/subr_witness.c	Sun Sep  6 13:26:51 2009	(r196890)
 +++ head/sys/kern/subr_witness.c	Sun Sep  6 13:31:05 2009	(r196891)
 @@ -469,8 +469,8 @@ static struct witness_lock_order_data *w
  static struct witness_lock_order_hash w_lohash;
  static int w_max_used_index = 0;
  static unsigned int w_generation = 0;
 -static const char *w_notrunning = "Witness not running\n";
 -static const char *w_stillcold = "Witness is still cold\n";
 +static const char w_notrunning[] = "Witness not running\n";
 +static const char w_stillcold[] = "Witness is still cold\n";
  
  
  static struct witness_order_list_entry order_lists[] = {
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/138557: commit references a PR
Date: Sat, 31 Oct 2009 12:26:56 +0000 (UTC)

 Author: antoine
 Date: Sat Oct 31 12:26:40 2009
 New Revision: 198715
 URL: http://svn.freebsd.org/changeset/base/198715
 
 Log:
   MFC r196891 to stable/8:
     Change w_notrunning and w_stillcold from pointer to array so that sizeof
     returns what is expected.
   
     PR:		kern/138557
     Discussed with:	brucec@
     MFC after:	1 month
 
 Modified:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
   stable/8/sys/dev/xen/xenpci/   (props changed)
   stable/8/sys/kern/subr_witness.c
 
 Modified: stable/8/sys/kern/subr_witness.c
 ==============================================================================
 --- stable/8/sys/kern/subr_witness.c	Sat Oct 31 12:22:23 2009	(r198714)
 +++ stable/8/sys/kern/subr_witness.c	Sat Oct 31 12:26:40 2009	(r198715)
 @@ -469,8 +469,8 @@ static struct witness_lock_order_data *w
  static struct witness_lock_order_hash w_lohash;
  static int w_max_used_index = 0;
  static unsigned int w_generation = 0;
 -static const char *w_notrunning = "Witness not running\n";
 -static const char *w_stillcold = "Witness is still cold\n";
 +static const char w_notrunning[] = "Witness not running\n";
 +static const char w_stillcold[] = "Witness is still cold\n";
  
  
  static struct witness_order_list_entry order_lists[] = {
 _______________________________________________
 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: patched->closed 
State-Changed-By: antoine 
State-Changed-When: Sat Oct 31 12:32:14 UTC 2009 
State-Changed-Why:  
Fixed in stable/8 too. 

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