From owner-freebsd-bugs@FreeBSD.ORG Sat Feb 15 23:40:01 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.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 BEF0FC96 for ; Sat, 15 Feb 2014 23:40:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 932261450 for ; Sat, 15 Feb 2014 23:40:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id s1FNe1m2072385 for ; Sat, 15 Feb 2014 23:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s1FNe118072384; Sat, 15 Feb 2014 23:40:01 GMT (envelope-from gnats) Date: Sat, 15 Feb 2014 23:40:01 GMT Message-Id: <201402152340.s1FNe118072384@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: oliver Subject: Re: bin/186697: calendar(1): -A -B -t not working correctly X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: oliver List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Feb 2014 23:40:01 -0000 The following reply was made to PR bin/186697; it has been noted by GNATS. From: oliver 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 */