From ba0e6bb8388cb8048d11f14d174f8526b0c4cfbc Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 8 Dec 2018 13:07:32 -0700 Subject: [PATCH] runtime/rfc2822-headers: Watch out for eof-object. And leave parse-error calls in tail position, so as not to frustrate a debugger expecting to return the correct answer. --- src/runtime/rfc2822-headers.scm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/runtime/rfc2822-headers.scm b/src/runtime/rfc2822-headers.scm index cf4807937..fd7aae296 100644 --- a/src/runtime/rfc2822-headers.scm +++ b/src/runtime/rfc2822-headers.scm @@ -191,26 +191,32 @@ USA. byte (builder))) ((fix:= 13 byte) - (if (fix:= 10 (peek-u8 port)) - (read-u8 port) - (parse-error port "Invalid line ending:" - 'read-ascii-line)) + (let ((byte (peek-u8 port))) + (cond ((eof-object? byte) + (parse-error port "Truncated line ending:" + 'read-ascii-line)) + ((fix:= 10 byte) + (read-u8 port)) + (else + (parse-error port "Invalid line ending:" + 'read-ascii-line)))) (builder)) ((fix:= 10 byte) - (parse-error port "Invalid line ending:" 'read-ascii-line) - (builder)) + (parse-error port "Invalid line ending:" 'read-ascii-line)) ((and (fix:<= 32 byte) (fix:<= byte 126)) (builder (integer->char byte)) (loop)) (else (parse-error port "Illegal character:" 'read-ascii-line) - (loop))))))))) + )))))))) (define (peek-ascii-char port) (let ((byte (peek-u8 port))) - (if (eof-object? byte) - byte - (integer->char byte)))) + (cond ((eof-object? byte) + byte) + ((and (fix:<= 32 byte) (fix:<= byte 126)) + (integer->char byte)) + (else (parse-error port "Illegal character:" 'peek-ascii-char))))) (define (skip-wsp-left string start end) (let loop ((i start)) -- 2.25.1