From nobody@FreeBSD.org  Wed Feb 12 17:48:11 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id AF414392
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 12 Feb 2014 17:48:11 +0000 (UTC)
Received: from newred.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 9B5261B11
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 12 Feb 2014 17:48:11 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by newred.freebsd.org (8.14.7/8.14.7) with ESMTP id s1CHmBUi090867
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 12 Feb 2014 17:48:11 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.7/8.14.7/Submit) id s1CHmBCZ090866;
	Wed, 12 Feb 2014 17:48:11 GMT
	(envelope-from nobody)
Message-Id: <201402121748.s1CHmBCZ090866@cgiserv.freebsd.org>
Date: Wed, 12 Feb 2014 17:48:11 GMT
From: kaltheat <kaltheat@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: calendar(1): -A -B -t not working correctly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         186697
>Category:       bin
>Synopsis:       calendar(1): -A -B -t not working correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 12 17:50:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Mon Feb 17 03:30:00 UTC 2014
>Originator:     kaltheat
>Release:        FreeBSD 9.2-RELEASE amd64
>Organization:
>Environment:
>Description:
Hi,

calendar command-line parameters -A and -B do not work as stated in man-page.

$ date
Wed Feb 12 18:38:42 CET 2014
$ cat .calendar/calendar
2013/02/12      test
2014/02/13      test1
$ calendar
Feb 13  test1
$ calendar -A 1
Feb 13  test1
$ calendar -B 1
$ calendar -t 11.02.2014
$ calendar -t 12.02.2014
Feb 13  test1
$ calendar -t 13.02.2014
Feb 13  test1

As it is said in man-page -B and -A should "print lines from today and ...". As you can see -t is strange too.

Regards,
kaltheat

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: kaltheat@googlemail.com
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/186697: calendar(1): -A -B -t not working correctly
Date: Wed, 12 Feb 2014 18:54:39 +0100

 Another nasty bug:
 
 $ calendar -A -1
 Segmentation fault (core dumped)
 $ calendar -B -1
 Segmentation fault (core dumped)
 
 
 

From: kaltheat@googlemail.com
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/186697: calendar(1): -A -B -t not working correctly
Date: Wed, 12 Feb 2014 19:11:53 +0100

 I'm unable to read and write correctly!
 
 $ cat .calendar/calendar
 2013/02/12 test
 ^^^^
 
 When doing it right:
 $ cat .calendar/calendar
 2014/02/12      test
 2014/02/13      test1
 
 -A, -B, -t work as described in man-page!
 
 Except:
 $ calendar -A 0
 Feb 12  test
 Feb 13  test1
 $ calendar -B 0
 Feb 12  test
 Feb 13  test1
 
 And segfault on bad input still exists ...
 
 Sorry,
 kaltheat
 
 

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org, kaltheat@gmail.com
Cc:  
Subject: Re: bin/186697: calendar(1): -A -B -t not working correctly
Date: Sun, 16 Feb 2014 00:37:34 +0100

 I checked that and the segfault is due to how the program handles the
 given arguments. The segfault only happens when year and month are the
 same, and only days differ. But due to the structure of the program,
 this leads to other calculation problems when using bigger values...
 
 For example:
 
 calendar -A -20  # does not print out correct values
 
 $ date
 So 16 Feb 2014 00:30:29 CET
 
 $ calendar -A -20
 16 Feb 	test2
 17 Feb 	test3
 18 Feb 	test4
 $ calendar -B 10
 14 Feb 	testx
 15 Feb 	test1
 16 Feb 	test2
 
 
 calendar assumes that date1 generated by (now - SECONDSOFDAY*(arg -B))
 is smaller than date2 (now + SECONDSOFDAY*(arg -A)) which happens only
 to be always true if you use positive integers for both. Failing that,
 the corresponding date is not calculated leading to a null pointer
 when month and day are the same, else wrong calculations are executed.
 This is also an issue for "-W". 
 
 The man page intends that you should use positive numbers (forward,
 future for -A, and backward, past for -B) for "-A" and "-B", so it could
 be the easiest fix to check the command line args for negative numbers
 and exit(1). (see below)
 
 The second issue "-A 0 -B 0 not working":
 
 That means if you only specify one argument -A or -B to be zero and the
 other argument not set or both set to zero, the program uses the default
 output (range from now to now+1d and on a friday from now to now+3d). If
 you specify -A or -B to be greater than 0 or set -W that default
 behaviour is not used anymore. 
 
 That may be an issue, but it depends on what was intended.
 
 
 
 A possible fix for the invalid parameter issue (segfault), also fixes
 -W:
 
 
 --- calendar.c	2014-02-15 21:51:29.000000000 +0100
 +++ /usr/src/usr.bin/calendar/calendar.c	2014-01-16
 21:36:28.000000000 +0100 @@ -96,18 +96,10 @@
  
  		case 'A': /* days after current date */
  			f_dayAfter = atoi(optarg);
 -			if(f_dayAfter<0) {
 -				errno = EINVAL;
 -			  	err(1, NULL);	
 -			}
  			break;
  
  		case 'B': /* days before current date */
  			f_dayBefore = atoi(optarg);
 -			if(f_dayBefore<0) {
 -				errno = EINVAL;
 -				err(1,NULL);
 -			}
  			break;
  
  		case 'D': /* debug output of sun and moon info */
 
 

From: oliver <oliver@beefrankly.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/186697: calendar(1): -A -B -t not working correctly
Date: Sun, 16 Feb 2014 01:13:31 +0100

 --MP_/wl6N.RZXvRZ5J9CjM=wVyF.
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 added a possible patch as attachment.
 --MP_/wl6N.RZXvRZ5J9CjM=wVyF.
 Content-Type: text/plain
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=patch.txt
 
 --- /usr/src/usr.bin/calendar/calendar.c	2014-01-16 21:36:28.000000000 +0100
 +++ calendar.c	2014-02-16 01:07:06.000000000 +0100
 @@ -96,10 +96,18 @@
  
  		case 'A': /* days after current date */
  			f_dayAfter = atoi(optarg);
 +			if (f_dayAfter < 0) {
 +				errno = EINVAL;
 +				err(1, NULL);
 +			} 
  			break;
  
  		case 'B': /* days before current date */
  			f_dayBefore = atoi(optarg);
 +			if (f_dayBefore < 0) {
 +				errno = EINVAL;
 +				err(1, NULL);
 +			} 
  			break;
  
  		case 'D': /* debug output of sun and moon info */
 
 --MP_/wl6N.RZXvRZ5J9CjM=wVyF.--
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Mon Feb 17 03:24:24 UTC 2014 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186697 
State-Changed-From-To: open->patched 
State-Changed-By: eadler 
State-Changed-When: Mon Feb 17 03:24:42 UTC 2014 
State-Changed-Why:  
committed in r262011 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/186697: commit references a PR
Date: Mon, 17 Feb 2014 03:24:08 +0000 (UTC)

 Author: eadler
 Date: Mon Feb 17 03:24:00 2014
 New Revision: 262011
 URL: http://svnweb.freebsd.org/changeset/base/262011
 
 Log:
   calendar(1): don't segfault in invalid input
   
   When the user supplies an invalid number of days provide a useful error message
   instead of segfaulting.
   
   PR:		bin/186697
   Reported by:	kaltheat <kaltheat@gmail.com>
   Submitted by:	oliver <oliver@beefrankly.org> (older version)
 
 Modified:
   head/usr.bin/calendar/calendar.c
 
 Modified: head/usr.bin/calendar/calendar.c
 ==============================================================================
 --- head/usr.bin/calendar/calendar.c	Mon Feb 17 02:24:58 2014	(r262010)
 +++ head/usr.bin/calendar/calendar.c	Mon Feb 17 03:24:00 2014	(r262011)
 @@ -96,10 +96,14 @@ main(int argc, char *argv[])
  
  		case 'A': /* days after current date */
  			f_dayAfter = atoi(optarg);
 +			if (f_dayAfter < 0)
 +				errx(1, "number of days must be positive");
  			break;
  
  		case 'B': /* days before current date */
  			f_dayBefore = atoi(optarg);
 +			if (f_dayBefore < 0)
 +				errx(1, "number of days must be positive");
  			break;
  
  		case 'D': /* debug output of sun and moon info */
 _______________________________________________
 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"
 
>Unformatted:
