Bug 892234 - calendar mismatches entries during "Friday through Monday" processing (with fix)
Summary: calendar mismatches entries during "Friday through Monday" processing (with fix)
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: calendar
Version: el6
Hardware: x86_64
OS: Linux
Target Milestone: ---
Assignee: David Cantrell
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2013-01-06 02:58 UTC by Luke Mewburn
Modified: 2013-02-13 19:08 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2013-02-13 19:08:01 UTC

Attachments (Terms of Use)
fix for "calendar-1.25-linux.patch" (392 bytes, text/plain)
2013-01-06 02:58 UTC, Luke Mewburn
no flags Details

Description Luke Mewburn 2013-01-06 02:58:43 UTC
Created attachment 673229 [details]
fix for "calendar-1.25-linux.patch"

Description of problem:

Sometimes calendar outputs a previous entry with today's date.

I've noticed this for a while when run out of crontab;
I'll get notification of yesterday's entry with today's date.

For example, if there are two entries in .calendar:
  Jan 3  Today is Thursday January 3
  Jan 4  Today is Friday January 4

Run calendar on Friday Jan 4, and the output will be:
  Jan 4   Today is Thursday January 3
  Jan 4   Today is Friday January 4

The first entry is erroneous; the date is wrong.

Version-Release number of selected component (if applicable):


How reproducible:

Upon further debugging with the source from the SRPM and gdb, I managed to reproduce this easily.

It turns out the bug triggers any time calendar is executing the documented behaviour "On Fridays, events on Friday through Monday are displayed."

Steps to Reproduce:
1. Create a calendar file ("~/testcal") with the entries:

Jan 3   Test for Jan 3 Thu
Jan 4   Test for Jan 4 Fri
Jan 5   Test for Jan 5 Sat
Jan 6   Test for Jan 6 Sun
Jan 7   Test for Jan 7 Mon
Jan 8   Test for Jan 8 Tue

2. Run calendar using the "test date" mode with different values for -t:

$ calendar -f ~/testcal -t 20130103

Should display Jan 3 and Jan 4

$ calendar -f ~/testcal -t 20130104

Should display Jan 4 through to Jan 7 (Because Jan 4 is a Friday)

Actual results:

$ calendar -f ~/testcal -t 20130104
Jan 04  Test for Jan 3 Thu
Jan 04  Test for Jan 4 Fri
Jan 05  Test for Jan 5 Sat
Jan 06  Test for Jan 6 Sun
Jan 07  Test for Jan 7 Mon

Notice how the first entry is "Jan 04  Test for Jan 3 Thu" ?

Expected results:

$ ./calendar -f ~/testcal -t 20130104
Jan 04  Test for Jan 4 Fri
Jan 05  Test for Jan 5 Sat
Jan 06  Test for Jan 6 Sun
Jan 07  Test for Jan 7 Mon

Additional info:

Code inspection of the source indicates that this is a bug in the EPEL patches to the upstream source.

Specifically, the file "calendar-1.25-linux.patch" contains the following change:

--- calendar-1.25/day.c.orig    2008-04-12 14:22:17.000000000 -1000
+++ calendar-1.25/day.c 2009-02-12 15:41:08.000000000 -1000
@@ -301,7 +300,8 @@ isnow(char *endp, int bodun)

        /* adjust bodun rate */
        if (bodun && !bodun_always)
-               bodun = !arc4random_uniform(3);
+               srandom(3);
+               bodun = random();

        /* Easter or Easter depending days */
        if (flags & F_SPECIAL)

The fault is obvious; the new line "bodun = random();" is unconditionally executed!

Wrapping those two new lines in their own block scope solves the problem.

I've attached a patch to apply after "calendar-1.25-linux.patch" but the former could just be incorporated into the latter.

Comment 1 David Cantrell 2013-01-28 19:27:53 UTC
Wow, that's embarrassing.  Thanks for the patch.  I've submitted a new build with the change.  Once it's done, I'll file a testing update for EPEL EL6.  I also checked the Fedora branches that are still supported and the braces are present on the block.

If you are the same Luke Mewburn that gave us lukemftp (or is tnftp), thanks.  It's my preferred FTP client.  I never have gotten around to adding a package for it to Fedora or EPEL, but one day.

Comment 2 Fedora Update System 2013-01-28 19:42:07 UTC
calendar-1.25-8.el6 has been submitted as an update for Fedora EPEL 6.

Comment 3 Luke Mewburn 2013-01-29 06:47:29 UTC
David: Yes, I'm the maintainer of tnftp (nee lukemftp). I'd use an EPEL package if you added one!

Comment 4 Fedora Update System 2013-01-29 20:00:31 UTC
Package calendar-1.25-8.el6:
* should fix your issue,
* was pushed to the Fedora EPEL 6 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=epel-testing calendar-1.25-8.el6'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 5 Luke Mewburn 2013-01-30 04:52:34 UTC
calendar-1.25-8.el6 fixes the bug.  I've left a comment on the link in comment 4.

Comment 6 David Cantrell 2013-02-13 13:45:14 UTC
Update has cooked for 14 days in testing, so it's clear for the stable updates collection now.  I've pushed it to stable as it looks like both you and I have confirmed it works.

Now on to tnftp...where is the best place to fetch upstream code for that?  I use the code I find here:  ftp://ftp.netbsd.org/pub/NetBSD/misc/tnftp/

If there is a better location, let me know.  Otherwise I'll start putting together a tnftp package for Fedora and EPEL.  If you want to continue this discussion outside of Bugzilla, that's fine (and preferred).  Just use my work email address:  dcantrell@redhat.com

Comment 7 Fedora Update System 2013-02-13 19:08:03 UTC
calendar-1.25-8.el6 has been pushed to the Fedora EPEL 6 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.