Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localhost sendmail: (null): time_to_text: bsnprintf #1166

Open
timmydo opened this issue Jan 26, 2022 · 0 comments
Open

localhost sendmail: (null): time_to_text: bsnprintf #1166

timmydo opened this issue Jan 26, 2022 · 0 comments

Comments

@timmydo
Copy link

timmydo commented Jan 26, 2022

I'm seeing the following log when trying to run opensmtpd on GNU Guix:

localhost sendmail: (null): time_to_text: bsnprintf

Looking at the code, it is print here:

const char *
time_to_text(time_t when)
{
	struct tm *lt;
	static char buf[40];
	char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
			 "Jul","Aug","Sep","Oct","Nov","Dec"};
	const char *tz;
	long offset;

	lt = localtime(&when);
	if (lt == NULL || when == 0)
		fatalx("time_to_text: localtime");

#if HAVE_STRUCT_TM_TM_GMTOFF
	offset = lt->tm_gmtoff;
	tz = lt->tm_zone;
#elif defined HAVE_DECL_ALTZONE && defined HAVE_DECL_TIMEZONE
	offset = lt->tm_isdst > 0 ? altzone : timezone;
	tz = lt->tm_isdst > 0 ? tzname[1] : tzname[0];
#endif

	/* We do not use strftime because it is subject to locale substitution*/
	if (!bsnprintf(buf, sizeof(buf),
	    "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)",
	    day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon],
	    lt->tm_year + 1900,
	    lt->tm_hour, lt->tm_min, lt->tm_sec,
	    offset >= 0 ? '+' : '-',
	    abs((int)offset / 3600),
	    abs((int)offset % 3600) / 60,
	    tz))
		fatalx("time_to_text: bsnprintf");

	return buf;
}

I don't see where HAVE_STRUCT_TM_TM_GMTOFF or HAVE_DECL_* are defined, so I'm assuming they're undefined. Which means that offset and tz are uninitialized. If tz is null, then printf will print something like this:

Wed, 31 Dec 1969 16:20:34 +0000 ((null))

which is 40 characters, or the exact size of the buffer, causing bsnprintf to fail and print that error. I haven't verified that is happening, but what would be the recommended fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant