From: Matt Birkholz Date: Sat, 8 Dec 2018 20:07:32 +0000 (-0700) Subject: runtime/rfc2822-headers: Watch out for eof-object. X-Git-Tag: mit-scheme-pucked-10.1.7~3^2~12 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=ba0e6bb8388cb8048d11f14d174f8526b0c4cfbc;p=mit-scheme.git 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. --- 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))