Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Feb 2014 23:40:01 GMT
From:      oliver <oliver@beefrankly.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/186697: calendar(1): -A -B -t not working correctly
Message-ID:  <201402152340.s1FNe118072384@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/186697; it has been noted by GNATS.

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 */
 
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402152340.s1FNe118072384>