And Still We Learn Nothing

People get upset with me when I say the bulk of OpenSource code is written by 12 year old boys, even if they happen to be north of 40 they simply never progressed past the age of 12 where it counts. This morning I’m digging into some rsyslog code and found this in datetime.c

/* the following table saves us from computing an additional date to get
 * the ordinal day of the year - at least from 1967-2099
 * Note: non-2038+ compliant systems (Solaris) will generate compiler
 * warnings on the post 2038-rollover years.
 */
static const int yearInSec_startYear = 1967;
/* for x in $(seq 1967 2099) ; do
 * printf %s', ' $(date --date="Dec 31 ${x} UTC 23:59:59" +%s)
 * done |fold -w 70 -s */
static const time_t yearInSecs[] = {
 -63158401, -31536001, -1, 31535999, 63071999, 94694399, 126230399,
 157766399, 189302399, 220924799, 252460799, 283996799, 315532799,
 347155199, 378691199, 410227199, 441763199, 473385599, 504921599,
 536457599, 567993599, 599615999, 631151999, 662687999, 694223999,
 725846399, 757382399, 788918399, 820454399, 852076799, 883612799,
 915148799, 946684799, 978307199, 1009843199, 1041379199, 1072915199,
 1104537599, 1136073599, 1167609599, 1199145599, 1230767999,
 1262303999, 1293839999, 1325375999, 1356998399, 1388534399,
 1420070399, 1451606399, 1483228799, 1514764799, 1546300799,
 1577836799, 1609459199, 1640995199, 1672531199, 1704067199,
 1735689599, 1767225599, 1798761599, 1830297599, 1861919999,
 1893455999, 1924991999, 1956527999, 1988150399, 2019686399,
 2051222399, 2082758399, 2114380799, 2145916799, 2177452799,
 2208988799, 2240611199, 2272147199, 2303683199, 2335219199,
 2366841599, 2398377599, 2429913599, 2461449599, 2493071999,
 2524607999, 2556143999, 2587679999, 2619302399, 2650838399,
 2682374399, 2713910399, 2745532799, 2777068799, 2808604799,
 2840140799, 2871763199, 2903299199, 2934835199, 2966371199,
 2997993599, 3029529599, 3061065599, 3092601599, 3124223999,
 3155759999, 3187295999, 3218831999, 3250454399, 3281990399,
 3313526399, 3345062399, 3376684799, 3408220799, 3439756799,
 3471292799, 3502915199, 3534451199, 3565987199, 3597523199,
 3629145599, 3660681599, 3692217599, 3723753599, 3755375999,
 3786911999, 3818447999, 3849983999, 3881606399, 3913142399,
 3944678399, 3976214399, 4007836799, 4039372799, 4070908799,
 4102444799};

 

Now, you don’t have to be a C programmer to understand that comment block at the top. The phrase

at least from 1967-2099

Switched my mind from casual reading to Holy Shit!

Even in a post y2k world we have people coding in an “I’ll be dead by then, who cares” way. Hopefully they weren’t planning on using this for birth dates. Won’t work for all of us born before 1967. Of course, a 12 year old boy wouldn’t think there is anyone that old left alive.

Found a really cool, if however aged, discussion on Y2038 here. Actually the cool part was a comment.

If the event to happen in 30 years is “expire this backup,” then you might be in trouble NOW, not in 2038. Add 30 years to today’s 32-bit time_t, and you get a date in the past. Your program looks for events to process, finds one that’s overdue (by 100 years!), and executes it. Oops, no more backup.

On my KDE Neon 64-bit desktop I found something interesting in /usr/include/x86_64-linux-gnu/bits/typesizes.h

/* X32 kernel interface is 64-bit. */
#if defined __x86_64__ && defined __ILP32__
# define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
# define __SYSCALL_ULONG_TYPE __UQUAD_TYPE
#else
# define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
# define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#endif

#define __TIME_T_TYPE __SYSCALL_SLONG_TYPE

Of course this wasn’t all nicely grouped together in the same spot like I show it here. So, we know that rsyslog, or at least this yerInSecs stuff cannot correctly compile on a 32-bit platform due to Y2038. This is probably the point of the Solaris comment, but, it really should have said a bit more than “compiler warnings.” Something like “don’t *&^(*&^(*&ing work.”

But, that’s my opinion and it’s allowed because it’s my blog.

 

One Comment

  1. The biggest problem with those kinds of shortcuts is a lack of public code reviews. If programmers knew their work (or comments that the algorithm only works between “1967-2099”) might be seen by their peers, or the boss, on “code review Friday” then they would never do such a thing. But I take some issue with your blanket criticism of Open Source because “the Open Source community” is reviewing code before it gets into production (they do it out of passion whereas many corporations got rid of code reviews to save money). If you look back at the whole debacle that caused SSL3 to morph into TLS1.0 (an IETF track project) then you will see a good example of how having more eyes on the problem is better. The original problem (which I have documented here: http://neilrieck.net/docs/openvms_notes_ssl.html ) was cause by confusion between “long” and “long long” which the IETF resolved by naming some “long long” variables to “uint64_t”

Leave a Reply