🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: demon.ip.developers
Article #506

Small timezone bug in KA9Q/SMTPSERV.C

#506
From: Peter Fokker
Date: Thu, 01 May 1997 00:00
109 lines
3449 bytes
I think I have discovered a small bug in the SMTP server code
(but this may be old news) for version 2.16d.

The code to retrieve a (valid) 3-char timezone works allright for
most of the timezones west of Greenwich. However, here on the
Continent we have a slight problem.

My DOS-environment says TZ=CET-1CES-2 because in the winter we
have Central European Time 1 hour ahead of GMT and in the summer we
have Central European Savings (Time) 2 hours ahead.

Alas, the code below insists on having the summertime start at
p[4] and end at p[6]. In my case that yields "1CE" which is
wrong. The best I can do is to set TZ=CET.CES but that is not how
it is supposed to be. BTW: I use GTZ to set the automatic
correction for summertime.

The code also fails when the offset from GMT is more than 9
hours: that is almost at the other end of the world so probably
not important<g>.

Anyway: I would say the code should be changed to something like this

if (ltm->tm_isdst == 0)
    {
    strncpy (tz, p, 3);
    }
else
    {
    for (p=&p[3]; ((isdigit(*p)) || (*p=='-') || (*p=='+')); )
         ++p;
    strncpy (tz, p, 3);
    }

allthough there are many other ways to solve it, e.g.

for (p=&p[4]; (isdigit(*p)); ) /* skip unary - or + or 1st digit via &p[4] */
         ++p;

Yet another option would be to forget about this fiddling with getenv("TZ")
and simply build on the existing logic as it is (in TZSET.C, with support
for both GTZ and TZ) and change the code in SMTPSERV.C to something like

if (ltm->tm_isdst == 0)
    strncpy (tz, tzname[0], 3);
else
    strncpy (tz, tzname[1], 3);

Also I think the TLA's "CET" and "CES" are not defined in the
appropriate RFC 822 (nor is BST if I recall correctly).

Question: Who is the official maintainer for the Demon-version of KA9Q?
In other words: who should I have emailed this message to rather than
posting it in this group?

--Peter Fokker

Original code starting at line 991 in SMTPSERV.C (KA9Q 2.16d) follows.
/*----------------------------------------------------------------*/
char *
     ptime (t)
long *t;
	{
	/* Print out the time and date field as "DAY day MONTH year hh:mm:ss
	 * ZONE" */
	register struct tm *ltm;
	static char tz[4];
	static char str[40];
	char *p, *getenv ();

	/* Read the system time */
	ltm = localtime (t);

	if (*tz == '\0')
		{
		if ((p = getenv ("TZ")) == NULL)
			{
			strcpy (tz, "UTC");
			}
		else
			{
			if (ltm->tm_isdst == 0)
				{
				strncpy (tz, p, 3);
				}
			else
				{
				strncpy (tz, p + 4, 3);
				}

			}

		}	/* if (*tz == '\0') */

	/* rfc 822 format */
	sprintf (str, "%s, %.2d %s %02d %02d:%02d:%02d %.3s\n",
			 Days[ltm->tm_wday],
			 ltm->tm_mday,
			 Months[ltm->tm_mon],
			 ltm->tm_year,
			 ltm->tm_hour,
			 ltm->tm_min,
			 ltm->tm_sec,
			 tz);
	return (str);
	}

/*----------------------------------------------------------------*/
Technical Details
Message-ID: <862463261snz@fokker.demon.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bb05,723f93803c1763df,start
X-Google-Attributes: gid10bb05,public
From: Peter@fokker.demon.nl (Peter Fokker)
Subject: Small timezone bug in KA9Q/SMTPSERV.C
Date: 1997/05/01
Message-ID: <862463261snz@fokker.demon.nl>
X-Deja-AN: 238582017
X-Mail2News-User: Peter@fokker.demon.nl
X-Mail2News-Path: fokker.demon.nl
Organization: Ingenieursbureau PSD
Reply-To: peter@fokker.demon.nl
Newsgroups: demon.ip.developers