From nobody@FreeBSD.org  Thu Jan 12 04:54:15 2012
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 9A5DA106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 04:54:15 +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 8961A8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 04:54:15 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0C4sFVp058932
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Jan 2012 04:54:15 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0C4sFC2058919;
	Thu, 12 Jan 2012 04:54:15 GMT
	(envelope-from nobody)
Message-Id: <201201120454.q0C4sFC2058919@red.freebsd.org>
Date: Thu, 12 Jan 2012 04:54:15 GMT
From: Devin Teske <dteske@vicor.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] tzsetup(8): Increase buffer size to hold error messages
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164038
>Category:       bin
>Synopsis:       [PATCH] tzsetup(8): Increase buffer size to hold error messages
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    wollman
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 12 05:00:26 UTC 2012
>Closed-Date:    Tue Apr 09 06:08:26 UTC 2013
>Last-Modified:  Tue Apr 09 06:08:26 UTC 2013
>Originator:     Devin Teske
>Release:        FreeBSD 9.0-RELEASE amd64
>Organization:
FIS Global, Inc.
>Environment:
FreeBSD scribe.vicor.com 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2010
root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
The prompt buffer is too small to hold error messages, and thus simply executing "tzsetup some/foo" results in:

Cannot read /usr/share/zoneinfo/some/foo: No such file or dir

(truncated portion is "ectory")

Bumping the prompt buffer from 64 bytes to 1024 seems like a modest solution.
>How-To-Repeat:
Exec as root: tzsetup some/foo
Notice error message "Cannot read %s: No such file or directory" is truncated by the 64-byte buffer.
>Fix:
See attached patch.txt

Patch attached with submission follows:

--- usr.sbin/tzsetup/tzsetup.c.orig	Fri Dec  2 11:19:10 2011
+++ usr.sbin/tzsetup/tzsetup.c	Wed Jan 11 18:58:01 2012
@@ -638,7 +638,7 @@ static int
 install_zoneinfo_file(const char *zoneinfo_file)
 {
 	char		buf[1024];
-	char		title[64], prompt[64];
+	char		title[64], prompt[1024];
 	struct stat	sb;
 	ssize_t		len;
 	int		fd1, fd2, copymode;


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: wollman 
State-Changed-When: Thu Jan 12 05:52:43 UTC 2012 
State-Changed-Why:  
Fixed in head, but in a slightly different way.  The changes should 
be MFH-able easily, so I'll leave this PR open for now. 


Responsible-Changed-From-To: freebsd-bugs->wollman 
Responsible-Changed-By: wollman 
Responsible-Changed-When: Thu Jan 12 05:52:43 UTC 2012 
Responsible-Changed-Why:  
Fixed in head, but in a slightly different way.  The changes should 
be MFH-able easily, so I'll leave this PR open for now. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/164038: commit references a PR
Date: Thu, 12 Jan 2012 05:50:47 +0000 (UTC)

 Author: wollman
 Date: Thu Jan 12 05:50:32 2012
 New Revision: 230005
 URL: http://svn.freebsd.org/changeset/base/230005
 
 Log:
   Use a reasonable-sized buffer when formatting error messages about
   installing zoneinfo.  While we're in the vicinity, add some missing
   error checking to eliminate an unhelpful error message when unlink()
   fails.
   
   /me is embarrassed by the quality of his 16-year-old code.
   The whole thing is awful and could stand a complete rewrite.
   
   PR:		164038
   Submitted by:	Devin Teske (but implemented differently)
 
 Modified:
   head/usr.sbin/tzsetup/tzsetup.c
 
 Modified: head/usr.sbin/tzsetup/tzsetup.c
 ==============================================================================
 --- head/usr.sbin/tzsetup/tzsetup.c	Thu Jan 12 05:47:28 2012	(r230004)
 +++ head/usr.sbin/tzsetup/tzsetup.c	Thu Jan 12 05:50:32 2012	(r230005)
 @@ -57,6 +57,13 @@ __FBSDID("$FreeBSD$");
  #define	_PATH_DB		"/var/db/zoneinfo"
  #define	_PATH_WALL_CMOS_CLOCK	"/etc/wall_cmos_clock"
  
 +#ifdef PATH_MAX
 +#define	SILLY_BUFFER_SIZE	2*PATH_MAX
 +#else
 +#warning "Somebody needs to fix this to dynamically size this buffer."
 +#define	SILLY_BUFFER_SIZE	2048
 +#endif
 +
  /* special return codes for `fire' actions */
  #define DITEM_FAILURE           1
  
 @@ -638,7 +645,7 @@ static int
  install_zoneinfo_file(const char *zoneinfo_file)
  {
  	char		buf[1024];
 -	char		title[64], prompt[64];
 +	char		title[64], prompt[SILLY_BUFFER_SIZE];
  	struct stat	sb;
  	ssize_t		len;
  	int		fd1, fd2, copymode;
 @@ -709,7 +716,18 @@ install_zoneinfo_file(const char *zonein
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
  
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
 +
  			fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
  			    S_IRUSR | S_IRGRP | S_IROTH);
  			if (fd2 < 0) {
 @@ -755,7 +773,17 @@ install_zoneinfo_file(const char *zonein
  					fprintf(stderr, "%s\n", prompt);
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
  			if (symlink(zoneinfo_file, path_localtime) < 0) {
  				snprintf(title, sizeof(title), "Error");
  				snprintf(prompt, sizeof(prompt),
 _______________________________________________
 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: Devin Teske <devin.teske@fisglobal.com>
To: <bug-followup@FreeBSD.org>, <dteske@vicor.com>
Cc:  
Subject: Re: bin/164038: [PATCH] tzsetup(8): Increase buffer size to hold error messages
Date: Mon, 7 May 2012 16:12:41 -0700

 Wollman,
 
 Shall I take and MFC so we can close? More testing needed?
 -- 
 Devin
 
 
 _____________
 The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/164038: commit references a PR
Date: Sun,  3 Mar 2013 17:39:43 +0000 (UTC)

 Author: dteske
 Date: Sun Mar  3 17:39:29 2013
 New Revision: 247721
 URL: http://svnweb.freebsd.org/changeset/base/247721
 
 Log:
   MFC r230005:
   
   Use a reasonable-sized buffer when formatting error messages about
   installing zoneinfo.  While we're in the vicinity, add some missing
   error checking to eliminate an unhelpful error message when unlink()
   fails.
   
   /me is embarrassed by the quality of his 16-year-old code.
   The whole thing is awful and could stand a complete rewrite.
   
   PR:		164038
   Submitted by:	Devin Teske (but implemented differently)
 
 Modified:
   stable/9/usr.sbin/tzsetup/tzsetup.c
 
 Modified: stable/9/usr.sbin/tzsetup/tzsetup.c
 ==============================================================================
 --- stable/9/usr.sbin/tzsetup/tzsetup.c	Sun Mar  3 17:33:59 2013	(r247720)
 +++ stable/9/usr.sbin/tzsetup/tzsetup.c	Sun Mar  3 17:39:29 2013	(r247721)
 @@ -56,6 +56,13 @@ __FBSDID("$FreeBSD$");
  #define	_PATH_DB		"/var/db/zoneinfo"
  #define	_PATH_WALL_CMOS_CLOCK	"/etc/wall_cmos_clock"
  
 +#ifdef PATH_MAX
 +#define	SILLY_BUFFER_SIZE	2*PATH_MAX
 +#else
 +#warning "Somebody needs to fix this to dynamically size this buffer."
 +#define	SILLY_BUFFER_SIZE	2048
 +#endif
 +
  static char	path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
  		path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN], 
  		path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
 @@ -523,7 +530,7 @@ static int
  install_zoneinfo_file(const char *zoneinfo_file)
  {
  	char		buf[1024];
 -	char		title[64], prompt[64];
 +	char		title[64], prompt[SILLY_BUFFER_SIZE];
  	struct stat	sb;
  	ssize_t		len;
  	int		fd1, fd2, copymode;
 @@ -594,7 +601,18 @@ install_zoneinfo_file(const char *zonein
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
  
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
 +
  			fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
  			    S_IRUSR | S_IRGRP | S_IROTH);
  			if (fd2 < 0) {
 @@ -640,7 +658,17 @@ install_zoneinfo_file(const char *zonein
  					fprintf(stderr, "%s\n", prompt);
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
  			if (symlink(zoneinfo_file, path_localtime) < 0) {
  				snprintf(title, sizeof(title), "Error");
  				snprintf(prompt, sizeof(prompt),
 _______________________________________________
 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: bin/164038: commit references a PR
Date: Mon,  4 Mar 2013 01:14:14 +0000 (UTC)

 Author: dteske
 Date: Mon Mar  4 01:14:06 2013
 New Revision: 247745
 URL: http://svnweb.freebsd.org/changeset/base/247745
 
 Log:
   MFC r230005:
   
   Use a reasonable-sized buffer when formatting error messages about
   installing zoneinfo.  While we're in the vicinity, add some missing
   error checking to eliminate an unhelpful error message when unlink()
   fails.
   
   /me is embarrassed by the quality of his 16-year-old code.
   The whole thing is awful and could stand a complete rewrite.
   
   PR:		164038
   Submitted by:	Devin Teske (but implemented differently)
 
 Modified:
   stable/8/usr.sbin/tzsetup/tzsetup.c
 
 Modified: stable/8/usr.sbin/tzsetup/tzsetup.c
 ==============================================================================
 --- stable/8/usr.sbin/tzsetup/tzsetup.c	Mon Mar  4 00:21:38 2013	(r247744)
 +++ stable/8/usr.sbin/tzsetup/tzsetup.c	Mon Mar  4 01:14:06 2013	(r247745)
 @@ -56,6 +56,13 @@ __FBSDID("$FreeBSD$");
  #define	_PATH_DB		"/var/db/zoneinfo"
  #define	_PATH_WALL_CMOS_CLOCK	"/etc/wall_cmos_clock"
  
 +#ifdef PATH_MAX
 +#define	SILLY_BUFFER_SIZE	2*PATH_MAX
 +#else
 +#warning "Somebody needs to fix this to dynamically size this buffer."
 +#define	SILLY_BUFFER_SIZE	2048
 +#endif
 +
  static char	path_zonetab[MAXPATHLEN], path_iso3166[MAXPATHLEN],
  		path_zoneinfo[MAXPATHLEN], path_localtime[MAXPATHLEN], 
  		path_db[MAXPATHLEN], path_wall_cmos_clock[MAXPATHLEN];
 @@ -523,7 +530,7 @@ static int
  install_zoneinfo_file(const char *zoneinfo_file)
  {
  	char		buf[1024];
 -	char		title[64], prompt[64];
 +	char		title[64], prompt[SILLY_BUFFER_SIZE];
  	struct stat	sb;
  	ssize_t		len;
  	int		fd1, fd2, copymode;
 @@ -594,7 +601,18 @@ install_zoneinfo_file(const char *zonein
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
  
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
 +
  			fd2 = open(path_localtime, O_CREAT | O_EXCL | O_WRONLY,
  			    S_IRUSR | S_IRGRP | S_IROTH);
  			if (fd2 < 0) {
 @@ -640,7 +658,17 @@ install_zoneinfo_file(const char *zonein
  					fprintf(stderr, "%s\n", prompt);
  				return (DITEM_FAILURE | DITEM_RECREATE);
  			}
 -			unlink(path_localtime);
 +			if (unlink(path_localtime) < 0 && errno != ENOENT) {
 +				snprintf(prompt, sizeof(prompt),
 +				    "Could not unlink %s: %s",
 +				    path_localtime, strerror(errno));
 +				if (usedialog) {
 +					snprintf(title, sizeof(title), "Error");
 +					dialog_msgbox(title, prompt, 8, 72, 1);
 +				} else
 +					fprintf(stderr, "%s\n", prompt);
 +				return (DITEM_FAILURE | DITEM_RECREATE);
 +			}
  			if (symlink(zoneinfo_file, path_localtime) < 0) {
  				snprintf(title, sizeof(title), "Error");
  				snprintf(prompt, sizeof(prompt),
 _______________________________________________
 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: dteske 
State-Changed-When: Tue Apr 9 06:07:46 UTC 2013 
State-Changed-Why:  
MFC'd to stable/8 via r247745 

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