>Synopsis: some weird MDA behaviour, including readers (mutt, dovecot) >Category: system >Environment: System : OpenBSD 6.4 Details : OpenBSD 6.4 (GENERIC) #349: Thu Oct 11 13:25:13 MDT 2018 dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC
Architecture: OpenBSD.amd64 Machine : amd64 >Description: Hi, earlier today someone posted a mail to misc@ which was not well received by mutt and dovecot becuase it has a "From " line in it. Usually those should be escaped when being delivered (with a >). I did speak to gilles on #opensmtpd about it but I was confused as to what the mail.local source code really is. I looked at the wrong part. So I set up my test environment and tried to reproduce on 6.4. I even produced a patch, later below. >How-To-Repeat: Script started on Thu Nov 8 16:49:30 2018 upsilon$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 upsilon.virgostar.net ESMTP OpenSMTPD helo remote 250 upsilon.virgostar.net Hello remote [127.0.0.1], pleased to meet you mail from: <p...@centroid.eu> 250 2.0.0: Ok rcpt to: <p...@schweinfurtdating.de> 250 2.1.5 Destination address valid: Recipient ok data 354 Enter mail, end with "." on a line by itself From: <p...@centroid.eu> To: <p...@schweinfurtdating.de> Subject: testing upsilon# head /var/mail/root >From dera...@do-not-reply.openbsd.org Sun Apr 15 06:30:00 MDT 2018 Return-Path: root Date: Apr 15 06:30:00 MDT 2018 From: dera...@do-not-reply.openbsd.org (Theo de Raadt) To: root Subject: Welcome to OpenBSD 6.3! This message attempts to describe the most basic initial questions that a system administrator of an OpenBSD box might have. You are urged to save this message for later reference. -peter . 250 2.0.0: b44401e2 Message accepted for delivery quit 221 2.0.0: Bye Connection closed by foreign host. upsilon$ mailq Mail version 8.1.2 01/15/2001. Type ? for help. "/var/mail/pjp": 2 messages 1 new 1 pjp@upsilon.virgo Thu Nov 8 16:49 31/1094 test >N 2 p...@centroid.eu Thu Nov 8 16:50 37/1318 testing & q Held 2 messages in /var/mail/pjp upsilon$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 upsilon.virgostar.net ESMTP OpenSMTPD helo remote 250 upsilon.virgostar.net Hello remote [127.0.0.1], pleased to meet you mail from: <p...@centroid.eu> 250 2.0.0: Ok rcptoto: <p...@schweinfurtdating.de> 250 2.1.5 Destination address valid: Recipient ok data 354 Enter mail, end with "." on a line by itself From: <p...@centroid.eu> To: <p...@schweinfurtdating.de> Subject: testing upsilon# head /var/mail/root >From dera...@do-not-reply.openbsd.org Sun Apr 15 06:30:00 MDT 2018 Return-Path: root Date: Apr 15 06:30:00 MDT 2018 From: dera...@do-not-reply.openbsd.org (Theo de Raadt) To: root Subject: Welcome to OpenBSD 6.3! This message attempts to describe the most basic initial questions that a system administrator of an OpenBSD box might have. You are urged to save this message for later reference. -peter . 250 2.0.0: 287ec1b8 Message accepted for delivery quit 221 2.0.0: Bye Connection closed by foreign host. upsilon$ mutt <shows 4 emails with Welcome mail> upsilon$ mail Mail version 8.1.2 01/15/2001. Type ? for help. "/var/mail/pjp": 3 messages 2 unread 1 pjp@upsilon.virgo Thu Nov 8 16:49 31/1094 test >U 2 p...@centroid.eu Thu Nov 8 16:50 38/1329 testing U 3 p...@centroid.eu Thu Nov 8 16:50 43/1395 testing & q Held 3 messages in /var/mail/pjp Script done on Thu Nov 8 16:51:53 2018 for some reason the "mail" program seems to render it right. But mutt doesn't it showed the Welcome mail that I "injected" as a seperate mail. >Fix: I wrote this patch to /usr/libexec/mail.local there was a variable that didn't seem to have any effect and it caused skipping the "From " check becuase it was always set to 0 except for the first line. Index: mail.local.c =================================================================== RCS file: /cvs/src/libexec/mail.local/mail.local.c,v retrieving revision 1.35 diff -u -p -u -r1.35 mail.local.c --- mail.local.c 12 Dec 2015 20:09:28 -0000 1.35 +++ mail.local.c 8 Nov 2018 16:05:47 -0000 @@ -117,7 +117,7 @@ storemail(char *from) { FILE *fp = NULL; time_t tval; - int fd, eline; + int fd; size_t len; char *line, *tbuf; @@ -131,7 +131,7 @@ storemail(char *from) (void)time(&tval); (void)fprintf(fp, "From %s %s", from, ctime(&tval)); - for (eline = 1, tbuf = NULL; (line = fgetln(stdin, &len));) { + for (tbuf = NULL; (line = fgetln(stdin, &len));) { /* We have to NUL-terminate the line since fgetln does not */ if (line[len - 1] == '\n') line[len - 1] = '\0'; @@ -143,13 +143,10 @@ storemail(char *from) tbuf[len] = '\0'; line = tbuf; } - if (line[0] == '\0') - eline = 1; - else { - if (eline && line[0] == 'F' && len > 5 && + if (line[0] != '\0') { + if (line[0] == 'F' && len > 5 && !memcmp(line, "From ", 5)) (void)putc('>', fp); - eline = 0; } (void)fprintf(fp, "%s\n", line); if (ferror(fp)) After this I tried to repeat this and couldn't: Script started on Thu Nov 8 17:00:47 2018 upsilon$ telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 upsilon.virgostar.net ESMTP OpenSMTPD helo remote 250 upsilon.virgostar.net Hello remote [127.0.0.1], pleased to meet you mail from:<<p...@centroid.eu> 250 2.0.0: Ok rcpt to: <p...@schweinfurtdating.de> 250 2.1.5 Destination address valid: Recipient ok data 354 Enter mail, end with "." on a line by itself From: <p...@centroid.eu> To: <p...@schweinfurtdating.de> Subject: testing upsilon# head /var/mail/root >From dera...@do-not-reply.openbsd.org Sun Apr 15 06:30:00 MDT 2018 Return-Path: root Date: Apr 15 06:30:00 MDT 2018 From: dera...@do-not-reply.openbsd.org (Theo de Raadt) To: root Subject: Welcome to OpenBSD 6.3! This message attempts to describe the most basic initial questions that a system administrator of an OpenBSD box might have. You are urged to save this message for later reference. -peter . 250 2.0.0: e0b1b265 Message accepted for delivery quit 221 2.0.0: Bye Connection closed by foreign host. upsilon$ mutt upsilon$ echo did not show did not show upsilon$ grep "^From"!/var/mail/pjp >From p...@upsilon.virgostar.net Thu Nov 8 16:49:05 2018 >From p...@upsilon.virgostar.net Thu Nov 8 16:56:03 2018 >From p...@centroid.eu Thu Nov 8 17:01:21 2018 upsilon$ grep ^>From " /var/mail/pjp >From dera...@do-not-reply.openbsd.org Sun Apr 15 06:30:00 MDT 2018 upsilon$ ^D Script done on Thu Nov 8 17:02:57 2018 It shows correct escaping of the "From " inside the mail. Please look these over and see if I made a mistake, however my mutt and dovecot seem to have made the mistake and the output is very misleading since there is no headers indicating where the mail came from and anyone can write into it. dmesg: OpenBSD 6.4 (GENERIC) #349: Thu Oct 11 13:25:13 MDT 2018 dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC real mem = 2080227328 (1983MB) avail mem = 2008080384 (1915MB) mpath0 at root scsibus0 at mpath0: 256 targets mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xf68c0 (9 entries) bios0: vendor Hetzner version "20171111" date 11/11/2017 bios0: Hetzner vServer acpi0 at bios0: rev 0 acpi0: sleep states S5 acpi0: tables DSDT FACP APIC HPET acpi0: wakeup devices acpitimer0 at acpi0: 3579545 Hz, 24 bits acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel Xeon Processor (Skylake, IBRS), 2100.35 MHz, 06-55-04 cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,SSE3,PCLMUL,SSSE3,FMA3,CX16,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,FSGSBASE,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,AVX512F,RDSEED,ADX,SMAP,CLWB,AVX512CD,IBRS,IBPB,ARAT,XSAVEOPT,XSAVEC,XGETBV1,MELTDOWN cpu0: 64KB 64b/line 2-way I-cache, 64KB 64b/line 2-way D-cache, 512KB 64b/line 16-way L2 cache cpu0: ITLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped cpu0: DTLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges cpu0: apic clock running at 1000MHz ioapic0 at mainbus0: apid 0 pa 0xfec00000, version 11, 24 pins acpihpet0 at acpi0: 100000000 Hz acpiprt0 at acpi0: bus 0 (PCI0) acpicpu0 at acpi0: C1(@1 halt!) "ACPI0006" at acpi0 not configured acpicmos0 at acpi0 "PNP0A06" at acpi0 not configured "PNP0A06" at acpi0 not configured "PNP0A06" at acpi0 not configured "QEMU0002" at acpi0 not configured "ACPI0010" at acpi0 not configured pvbus0 at mainbus0: KVM pci0 at mainbus0 bus 0 pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02 pcib0 at pci0 dev 1 function 0 "Intel 82371SB ISA" rev 0x00 pciide0 at pci0 dev 1 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 0 wired to compatibility, channel 1 wired to compatibility pciide0: channel 0 disabled (no drives) atapiscsi0 at pciide0 channel 1 drive 0 scsibus1 at atapiscsi0: 2 targets cd0 at scsibus1 targ 0 lun 0: <QEMU, QEMU DVD-ROM, 2.5+> ATAPI 5/cdrom removable cd0(pciide0:1:0): using PIO mode 4, DMA mode 2 uhci0 at pci0 dev 1 function 2 "Intel 82371SB USB" rev 0x01: apic 0 int 11 piixpm0 at pci0 dev 1 function 3 "Intel 82371AB Power" rev 0x03: apic 0 int 9 iic0 at piixpm0 vga1 at pci0 dev 2 function 0 "Bochs VGA" rev 0x02 wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation) wsdisplay0: screen 1-5 added (80x25, vt100 emulation) virtio0 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00 vio0 at virtio0: address 96:00:00:0e:36:85 virtio0: msix shared virtio1 at pci0 dev 4 function 0 "Qumranet Virtio SCSI" rev 0x00 vioscsi0 at virtio1: qsize 128 scsibus2 at vioscsi0: 255 targets sd0 at scsibus2 targ 0 lun 0: <QEMU, QEMU HARDDISK, 2.5+> SCSI3 0/direct fixed sd0: 19532MB, 512 bytes/sector, 40001536 sectors, thin virtio1: msix shared virtio2 at pci0 dev 5 function 0 "Qumranet Virtio Memory" rev 0x00 viomb0 at virtio2 virtio2: apic 0 int 10 virtio3 at pci0 dev 6 function 0 "Qumranet Virtio Console" rev 0x00 virtio3: no matching child driver; not configured isa0 at pcib0 isadma0 at isa0 fdc0 at isa0 port 0x3f0/6 irq 6 drq 2 com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo pckbc0 at isa0 port 0x60/5 irq 1 irq 12 pckbd0 at pckbc0 (kbd slot) wskbd0 at pckbd0: console keyboard, using wsdisplay0 pms0 at pckbc0 (aux slot) wsmouse0 at pms0 mux 0 pcppi0 at isa0 port 0x61 spkr0 at pcppi0 usb0 at uhci0: USB revision 1.0 uhub0 at usb0 configuration 1 interface 0 "Intel UHCI root hub" rev 1.00/1.00 addr 1 uhidev0 at uhub0 port 1 configuration 1 interface 0 "QEMU QEMU USB Tablet" rev 2.00/0.00 addr 2 uhidev0: iclass 3/0 ums0 at uhidev0: 3 buttons, Z dir wsmouse1 at ums0 mux 0 vscsi0 at root scsibus3 at vscsi0: 256 targets softraid0 at root scsibus4 at softraid0: 256 targets root on sd0a (7e80d329675cf4a8.a) swap on sd0b dump on sd0b fd0 at fdc0 drive 1: density unknown usbdevs: Controller /dev/usb0: addr 01: 8086:0000 Intel, UHCI root hub full speed, self powered, config 1, rev 1.00 driver: uhub0 addr 02: 0627:0001 QEMU, QEMU USB Tablet full speed, power 100 mA, config 1, rev 0.00, iSerialNumber 42 driver: uhidev0