~sircmpwn/hare-users

hare-message: message::read_header: Skip header fields with invalid values v2 PROPOSED

Max Schillinger: 1
 message::read_header: Skip header fields with invalid values

 1 files changed, 11 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-users/patches/52966/mbox | git am -3
Learn more about email & git

[PATCH hare-message v2] message::read_header: Skip header fields with invalid values Export this patch

Signed-off-by: Max Schillinger <max@mxsr.de>
---
This is <https://lists.sr.ht/~sircmpwn/hare-users/patches/51405> rebased to
master.

 message/header.ha | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/message/header.ha b/message/header.ha
index 1f75513..5d1fdd5 100644
--- a/message/header.ha
+++ b/message/header.ha
@@ -1,6 +1,7 @@
use ascii;
use bufio;
use bytes;
use encoding::utf8;
use errors;
use fmt;
use hash::fnv;
@@ -138,7 +139,7 @@ export fn header_add_raw(head: *header, kv: []u8) void = {
	const key = bytes::trim(kv[..colon], ' ', '\t');
	const key = canonical_mime_header_key(strings::fromutf8(key)!);
	let map = header_get_mapkey(head, key);
	const val = decode_header_value(kv[colon..]);
	const val = decode_header_value(kv[colon..])!;

	const field = alloc(new_header_field(key, val, alloc(kv...)));
	append(head.fields, field);
@@ -359,7 +360,13 @@ export fn read_header(
			continue;
		};

		const val = decode_header_value(kv[i+1..]);
		const val = match (decode_header_value(kv[i+1..])) {
		case encoding::utf8::invalid =>
			fmt::errorfln("Error: Invalid UTF8 in value for header key '{}'", key)!;
			continue;
		case let val: str =>
			yield val;
		};
		const val = decode_encoded_words(val);
		const field = alloc(header_field {
			raw = kv,
@@ -609,7 +616,7 @@ fn fold_line(v: []u8, max: size) ([]u8, []u8, bool) = {

// Decodes a header value, collapsing continuation lines as necessary. The
// caller must free the return value.
fn decode_header_value(v: []u8) str = {
fn decode_header_value(v: []u8) (str | encoding::utf8::invalid) = {
	const sink = memio::dynamic();
	for (true) {
		const i = match (bytes::index(v, '\n')) {
@@ -622,7 +629,7 @@ fn decode_header_value(v: []u8) str = {
		write_continued(&sink, v[..i]);
		v = v[i+1..];
	};
	return memio::string(&sink)!;
	return memio::string(&sink)?;
};

fn write_continued(sink: *memio::stream, v: []u8) void = {
-- 
2.45.1