unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf
@ 2022-01-26  5:51 Timmy Douglas via Bug reports for GNU Guix
  2023-11-21  7:09 ` Timmy Douglas via Bug reports for GNU Guix
  0 siblings, 1 reply; 5+ messages in thread
From: Timmy Douglas via Bug reports for GNU Guix @ 2022-01-26  5:51 UTC (permalink / raw)
  To: 53547


I recently installed opensmtpd and have been trying to send email. It
appears there is an error with the bsnprintf function:

$ ./sendmail -t
To: timmy
From: me 
Subject: hi

aoeueou
(press ^D)
sendmail: time_to_text: bsnprintf

I reported this issue here:
https://github.com/OpenSMTPD/OpenSMTPD/issues/1166

mcron appears to invoke sendmail with `-t`, which is how I discovered
the issue.

If anyone is trying to figure out how to setup the setuid on Guix
system, here is my config.scm file (I couldn't find anything online so
maybe this will help):

(operating-system
 ; ...
   (append (list (setuid-program
                  (program (file-append opensmtpd "/sbin/smtpctl"))
		  (setuid? #f)
		  (setgid? #t)
		  (user "root")
		  (group "smtpq"))
		 (setuid-program
                  (program (file-append opensmtpd "/sbin/sendmail"))
		  (setuid? #f)
		  (setgid? #t)
		  (user "root")
		  (group "smtpq")))
           %setuid-programs))

I tried building the latest opensmtpd from git, which required a few
other changes to patch the bug:



diff --git a/usr.sbin/smtpd/smtpc.c b/usr.sbin/smtpd/smtpc.c
index 49750dca..4ed506dc 100644
--- a/usr.sbin/smtpd/smtpc.c
+++ b/usr.sbin/smtpd/smtpc.c
@@ -114,8 +114,8 @@ parse_tls_options(char *opt)
                        servname = value;
                        break;
                case -1:
-                       if (suboptarg)
-                               fatalx("invalid TLS option \"%s\"", suboptarg);
+                 //if (suboptarg)
+                 //            fatalx("invalid TLS option \"%s\"", suboptarg);
                        fatalx("missing TLS option");
                }
        }
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 00c49cb7..3630ef1d 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -52,6 +52,8 @@
 #endif
 #include <limits.h>
 
+#include <grp.h>
+
 #include "smtpd.h"
 #include "parser.h"
 #include "log.h"
diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c
index 3ea04d89..9928d09b 100644
--- a/usr.sbin/smtpd/to.c
+++ b/usr.sbin/smtpd/to.c
@@ -176,7 +176,7 @@ const char *
 time_to_text(time_t when)
 {
        struct tm *lt;
-       static char buf[40];
+       static char buf[50];
        char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
        char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
                         "Jul","Aug","Sep","Oct","Nov","Dec"};
@@ -193,6 +193,9 @@ time_to_text(time_t when)
 #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];
+#else
+       offset = 0;
+       tz = "GMT";
 #endif
 
        /* We do not use strftime because it is subject to locale substitution*/




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf
  2022-01-26  5:51 bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf Timmy Douglas via Bug reports for GNU Guix
@ 2023-11-21  7:09 ` Timmy Douglas via Bug reports for GNU Guix
  2023-11-22 17:57   ` Nathan via Bug reports for GNU Guix
       [not found]   ` <87plzq7zwa.fsf@nckx>
  0 siblings, 2 replies; 5+ messages in thread
From: Timmy Douglas via Bug reports for GNU Guix @ 2023-11-21  7:09 UTC (permalink / raw)
  To: 53547; +Cc: Tobias Geerinckx-Rice


Tobias, I noticed you recently updated opensmtpd to 7.4.0 with commit
5e7f27d6ca7be84453e6d4de3d860b700ba3aef7.

I was curious if you or anyone else has seen this issue, and if I should
try submitting a patch to guix for it.


Timmy Douglas <mail@timmydouglas.com> writes:

> I recently installed opensmtpd and have been trying to send email. It
> appears there is an error with the bsnprintf function:
>
> $ ./sendmail -t
> To: timmy
> From: me 
> Subject: hi
>
> aoeueou
> (press ^D)
> sendmail: time_to_text: bsnprintf
>
> I reported this issue here:
> https://github.com/OpenSMTPD/OpenSMTPD/issues/1166
>
> mcron appears to invoke sendmail with `-t`, which is how I discovered
> the issue.
>
> If anyone is trying to figure out how to setup the setuid on Guix
> system, here is my config.scm file (I couldn't find anything online so
> maybe this will help):
>
> (operating-system
>  ; ...
>    (append (list (setuid-program
>                   (program (file-append opensmtpd "/sbin/smtpctl"))
> 		  (setuid? #f)
> 		  (setgid? #t)
> 		  (user "root")
> 		  (group "smtpq"))
> 		 (setuid-program
>                   (program (file-append opensmtpd "/sbin/sendmail"))
> 		  (setuid? #f)
> 		  (setgid? #t)
> 		  (user "root")
> 		  (group "smtpq")))
>            %setuid-programs))
>
> I tried building the latest opensmtpd from git, which required a few
> other changes to patch the bug:
>
>
>
> diff --git a/usr.sbin/smtpd/smtpc.c b/usr.sbin/smtpd/smtpc.c
> index 49750dca..4ed506dc 100644
> --- a/usr.sbin/smtpd/smtpc.c
> +++ b/usr.sbin/smtpd/smtpc.c
> @@ -114,8 +114,8 @@ parse_tls_options(char *opt)
>                         servname = value;
>                         break;
>                 case -1:
> -                       if (suboptarg)
> -                               fatalx("invalid TLS option \"%s\"", suboptarg);
> +                 //if (suboptarg)
> +                 //            fatalx("invalid TLS option \"%s\"", suboptarg);
>                         fatalx("missing TLS option");
>                 }
>         }
> diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
> index 00c49cb7..3630ef1d 100644
> --- a/usr.sbin/smtpd/smtpctl.c
> +++ b/usr.sbin/smtpd/smtpctl.c
> @@ -52,6 +52,8 @@
>  #endif
>  #include <limits.h>
>  
> +#include <grp.h>
> +
>  #include "smtpd.h"
>  #include "parser.h"
>  #include "log.h"
> diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c
> index 3ea04d89..9928d09b 100644
> --- a/usr.sbin/smtpd/to.c
> +++ b/usr.sbin/smtpd/to.c
> @@ -176,7 +176,7 @@ const char *
>  time_to_text(time_t when)
>  {
>         struct tm *lt;
> -       static char buf[40];
> +       static char buf[50];
>         char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
>         char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
>                          "Jul","Aug","Sep","Oct","Nov","Dec"};
> @@ -193,6 +193,9 @@ time_to_text(time_t when)
>  #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];
> +#else
> +       offset = 0;
> +       tz = "GMT";
>  #endif
>  
>         /* We do not use strftime because it is subject to locale substitution*/




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf
  2023-11-21  7:09 ` Timmy Douglas via Bug reports for GNU Guix
@ 2023-11-22 17:57   ` Nathan via Bug reports for GNU Guix
  2023-11-23  0:03     ` Timmy Douglas via Bug reports for GNU Guix
       [not found]   ` <87plzq7zwa.fsf@nckx>
  1 sibling, 1 reply; 5+ messages in thread
From: Nathan via Bug reports for GNU Guix @ 2023-11-22 17:57 UTC (permalink / raw)
  To: mail, 53547

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

I don't have this problem on my server.

I looked at your github issue page.
Those macros are defined by the `configure' script.
I can see that guix's `configure' output defines HAVE_STRUCT_TM_TM_GMTOFF in config.h.
(if neither of the #if match, then the `tz' pointer is likely garbage and the program will crash.)

A problem with your time zone configuration seems like a reasonable guess.
I'd check it with a simple C program like the one attached.


[-- Attachment #2: test program --]
[-- Type: application/octet-stream, Size: 213 bytes --]

// compile with
// gcc ./a.c
// run with
// ./a.out
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv){
	time_t now=time(NULL);
	struct tm *lt=localtime(&now);
	printf("\"%s\"\n",lt->tm_zone);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf
  2023-11-22 17:57   ` Nathan via Bug reports for GNU Guix
@ 2023-11-23  0:03     ` Timmy Douglas via Bug reports for GNU Guix
  0 siblings, 0 replies; 5+ messages in thread
From: Timmy Douglas via Bug reports for GNU Guix @ 2023-11-23  0:03 UTC (permalink / raw)
  To: nathan_mail, 53547

Nathan <nathan_mail@nborghese.com> writes:

> I don't have this problem on my server.
>
> I looked at your github issue page.
> Those macros are defined by the `configure' script.
> I can see that guix's `configure' output defines HAVE_STRUCT_TM_TM_GMTOFF in config.h.
> (if neither of the #if match, then the `tz' pointer is likely garbage and the program will crash.)
>
> A problem with your time zone configuration seems like a reasonable guess.
> I'd check it with a simple C program like the one attached.

your app prints my timezone as expected. if you run something like this
does it work for you?

cat << EOF | /run/setuid-programs/sendmail $(whoami)
To: $(whoami)
Subject: test


blah
EOF

for me, it prints:

sendmail: time_to_text: bsnprintf


my config.scm:


(operating-system
  ...
  (setuid-programs
   (append (list (setuid-program
                  (program (file-append opensmtpd "/sbin/smtpctl"))
		 (setuid? #f)
		 (setgid? #t)
		 (user "root")
		 (group "smtpq"))
		(setuid-program
                  (program (file-append opensmtpd "/sbin/sendmail"))
		 (setuid? #f)
		 (setgid? #t)
		 (user "root")
		 (group "smtpq")))
           %setuid-programs))




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf
       [not found]   ` <87plzq7zwa.fsf@nckx>
@ 2023-12-02  5:15     ` Timmy Douglas via Bug reports for GNU Guix
  0 siblings, 0 replies; 5+ messages in thread
From: Timmy Douglas via Bug reports for GNU Guix @ 2023-12-02  5:15 UTC (permalink / raw)
  To: me, 53547

Tobias Geerinckx-Rice <me@tobias.gr> writes:

> [snip]
> I'm running opensmtpd@7.4.0p1.  Have you tried that yet?
>
> Guix would certainly accept a patch to fix a bug, but I'm also 
> paranoid and would prefer to first see some response from upstream 
> that this is the correct diagnosis.


So I found a workaround on my computer with that script that didn't seem
to repro. If I set TZ=UTC instead of what I had
(TZ=America/Los_Angeles), I was able to make that script work. I should
be able to propagate that to mcron and work around the issue...


What I tried before that:

When I straced sendmail earlier I saw this:

[pid 29134] newfstatat(5, "", {st_mode=S_IFSOCK|0777, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 29134] read(5, "220 localhost ESMTP OpenSMTPD\r\n", 4096) = 31
[pid 29134] write(5, "EHLO localhost\r\n", 16) = 16
[pid 29134] read(5, "250-localhost Hello localhost [l"..., 4096) = 128
[pid 29134] write(5, "MAIL FROM:<timmy@localhost>  \r\n", 31) = 31
[pid 29134] read(5, "250 2.0.0 Ok\r\n", 4096) = 14
[pid 29134] write(5, "RCPT TO:<root@localhost> \r\n", 27) = 27
[pid 29134] read(5, "250 2.1.5 Destination address va"..., 4096) = 51
[pid 29134] write(5, "DATA\r\n", 6)     = 6
[pid 29134] read(5, "354 Enter mail, end with \".\" on "..., 4096) = 50
[pid 29134] write(2, "sendmail: time_to_text: bsnprint"..., 34sendmail: time_to_text: bsnprintf
) = 34
[pid 29134] write(5, "From: timmy <timmy@localhost>\r\n", 31) = 31
[pid 29134] exit_group(1)               = ?

It looks like the code of the sendmail client will try to add a Date
header if one wasn't passed to the client. (smtp_session.c:2647)

I was able to send an email directly with telnet, so that verified the
code wasn't on the server. I tried throwing together a standalone repro
(below), but didn't have any luck reproducing it. With opensmtpd's
sendmail being setgid, I didn't really feel like debugging further.

// compile with
// gcc ./a.c
// run with
// ./a.out
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <stdlib.h>

int
bsnprintf(char *str, size_t size, const char *format, ...)
{
	int ret;
	va_list ap;

	va_start(ap, format);
	ret = vsnprintf(str, size, format, ap);
	va_end(ap);
	if (ret < 0 || (size_t)ret >= size)
		return 0;

	return 1;
}


const char *
time_to_text(time_t when)
{
	struct tm *lt;
	static char buf[40];
	const char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	const 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)
		perror("time_to_text: localtime");

#if 1
	offset = lt->tm_gmtoff;
	tz = lt->tm_zone;
#elif 0
	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))
		perror("time_to_text: bsnprintf");
	else
	  {
	    printf("'%s'", buf);
	  }
	return buf;
}

int main(int argc, char** argv){
	time_t now=time(NULL);
	time_to_text(now);
	struct tm *lt=localtime(&now);
}




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-02  5:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26  5:51 bug#53547: Error sending email with OpenSMTPD, fatal: time_to_text: bsnprintf Timmy Douglas via Bug reports for GNU Guix
2023-11-21  7:09 ` Timmy Douglas via Bug reports for GNU Guix
2023-11-22 17:57   ` Nathan via Bug reports for GNU Guix
2023-11-23  0:03     ` Timmy Douglas via Bug reports for GNU Guix
     [not found]   ` <87plzq7zwa.fsf@nckx>
2023-12-02  5:15     ` Timmy Douglas via Bug reports for GNU Guix

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).