From f35bd77442e277b93ad3314882490c7e37cf01d1 Mon Sep 17 00:00:00 2001 From: mainzelm Date: Tue, 7 Jan 2003 14:58:13 +0000 Subject: [PATCH] Check string indices and simplify calls to set-port-buffering. --- scsh/rw.scm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scsh/rw.scm b/scsh/rw.scm index 317e449..c0ff5b3 100644 --- a/scsh/rw.scm +++ b/scsh/rw.scm @@ -16,9 +16,12 @@ (let-optionals args ((fd/port (current-input-port)) (start 0) (end (string-length s))) + (if (bogus-substring-spec? s start end) + (error "Bad substring indices" s start end)) + (cond ((integer? fd/port) (let ((port (fdes->inport fd/port))) - (set-port-buffering port bufpol/block (max (- end start) 0)) + (set-port-buffering port bufpol/block (- end start)) (read-string!/partial port start end))) (else ; no differnce between fd/ports and s48 ports @@ -51,9 +54,12 @@ (let-optionals args ((fd/port (current-input-port)) (start 0) (end (string-length s))) + (if (bogus-substring-spec? s start end) + (error "Bad substring indices" s start end)) + (cond ((integer? fd/port) (let ((port (fdes->inport fd/port))) - (set-port-buffering port bufpol/block (max (- end start) 0)) + (set-port-buffering port bufpol/block (- end start)) (read-string! port start end))) (else ; no differnce between fd/port and s48 ports @@ -79,9 +85,12 @@ (let-optionals args ((fd/port (current-output-port)) (start 0) (end (string-length s))) + (if (bogus-substring-spec? s start end) + (error "Bad substring indices" s start end)) + (cond ((integer? fd/port) (let ((port (fdes->outport fd/port))) - (set-port-buffering port bufpol/block (max (- end start) 0)) + (set-port-buffering port bufpol/block (- end start)) (write-string/partial s port start end))) (else ;; the only way to implement this, would be to use @@ -98,8 +107,11 @@ See the RELEASE file for details"))))) (let-optionals args ((fd/port (current-output-port)) (start 0) (end (string-length s))) + (if (bogus-substring-spec? s start end) + (error "Bad substring indices" s start end)) + (cond ((integer? fd/port) (let ((port (fdes->outport fd/port))) - (set-port-buffering port bufpol/block (max (- end start) 0)) + (set-port-buffering port bufpol/block (- end start)) (write-string s port start end))) (else (write-block s start (- end start) fd/port)))))