From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outgoing.selfhost.de ([82.98.87.70]) by ewsd; Sat Sep 12 17:20:12 EDT 2020 Received: (qmail 3066 invoked from network); 12 Sep 2020 21:19:50 -0000 Received: from unknown (HELO mx03.bss-wf.de) (postmaster@emdtgvmf.mail.selfhost.de@84.150.42.130) by mailout.selfhost.de with ESMTPA; 12 Sep 2020 21:19:50 -0000 Received: by mx03.bss-wf.de (Postfix, from userid 1000) id 82B503DD7C; Sat, 12 Sep 2020 23:19:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mx03 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 Received: from 9nb.pala (p5b3bc91e.dip0.t-ipconnect.de [91.59.201.30]) by mx03.bss-wf.de (Postfix) with ESMTPSA id 905F23DD7A for <9front@9front.org>; Sat, 12 Sep 2020 23:19:49 +0200 (CEST) Message-ID: <84CF8B87EF0CECB4DA21B1FCEF84A0C7@bss-wf.de> To: 9front@9front.org Subject: Re: [9front] [Bug] [PATCH] Mail cannot cope with multi-line header fields Date: Sat, 12 Sep 2020 23:19:48 +0200 From: theinicke@bss-wf.de In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: browser-aware blockchain interface markup realtime-java locator Sorry for the noise. But if the solution of removing line breaks from all fields in just the info file (and not taking into account that by design some info fields never contain line breaks) is considered, please regard the following patch instead; as the former contained useless code. -- Tobias Heinicke diff -r 9f6e77258f69 sys/src/cmd/upas/fs/fs.c --- a/sys/src/cmd/upas/fs/fs.c Thu Sep 10 16:26:42 2020 -0700 +++ b/sys/src/cmd/upas/fs/fs.c Sat Sep 12 23:09:31 2020 +0200 @@ -387,6 +387,26 @@ return s; } +int +unfold(char *s, int len, char **pp) +{ + int i, u; + char c; + char *p; + + p = malloc(len); + u = 0; + for(i = 0; i < len; i++) { + c = s[i]; + if(c != '\n') { + p[u++] = c; + } + } + + *pp = p; + return u; +} + static int fileinfo(Mailbox *mb, Message *m, int t, char **pp) { @@ -568,7 +588,7 @@ int readinfo(Mailbox *mb, Message *m, char *buf, long off, int count) { - char *s, *p, *e; + char *s, *p, *e, *q; int i, n; long off0; @@ -584,18 +604,24 @@ } if((n = fileinfo(mb, m, infofields[i], &p)) < 0) return -1; + + /* remove line breaks in fields s.t. consumers of info + can rely on finding particular field on certain line */ + n = unfold(p, n, &q); + if(off > n){ off -= n + 1; continue; } if(off){ n -= off; - p += off; + q += off; off = 0; } if(s + n > e) n = e - s; - memcpy(s, p, n); + memcpy(s, q, n); + free(q); s += n; if(s < e) *s++ = '\n';