From: theinicke@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 [thread overview]
Message-ID: <84CF8B87EF0CECB4DA21B1FCEF84A0C7@bss-wf.de> (raw)
In-Reply-To: <E5B90C9FB0641679CAAC6A91690E70ED@bss-wf.de>
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';
next prev parent reply other threads:[~2020-09-12 21:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 19:33 theinicke
2020-09-09 19:50 ` [9front] " ori
2020-09-10 6:27 ` theinicke
2020-09-10 19:58 ` theinicke
2020-09-10 21:12 ` ori
2020-09-11 21:08 ` theinicke
2020-09-12 21:19 ` theinicke [this message]
2020-09-12 22:58 ` ori
2020-09-14 21:49 ` theinicke
2020-09-17 23:01 ` ori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84CF8B87EF0CECB4DA21B1FCEF84A0C7@bss-wf.de \
--to=theinicke@bss-wf.de \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).