>From 5e5ec9ad951e695ce1a5604116f7f770ca6b9771 Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Tue, 31 Oct 2017 21:40:04 +1300 Subject: [PATCH] Move read-string rewrite into types.db After 25064a3c, the c-platform rewrite for 'read-string' would disregard its second argument and use an internal version of the procedure whenever at least one argument was given (instead of *exactly* one), leading to potentially unsafe behaviour since the type of that second argument then wouldn't be checked. To fix this, we move the rewrite into types.db so that the procedure is only rewritten when both of its arguments match the expected types. --- c-platform.scm | 1 - types.db | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/c-platform.scm b/c-platform.scm index d2323fe8..523ad20f 100644 --- a/c-platform.scm +++ b/c-platform.scm @@ -1053,7 +1053,6 @@ (rewrite 'scheme#read-char 23 0 '##sys#read-char/port '##sys#standard-input) (rewrite 'scheme#write-char 23 1 '##sys#write-char/port '##sys#standard-output) -(rewrite 'chicken.io#read-string 23 1 'chicken.io#read-string/port '##sys#standard-input) (rewrite 'chicken.string#substring=? 23 2 '##sys#substring=? 0 0 #f) (rewrite 'chicken.string#substring-ci=? 23 2 '##sys#substring-ci=? 0 0 #f) (rewrite 'chicken.string#substring-index 23 2 '##sys#substring-index 0) diff --git a/types.db b/types.db index 321e8ef9..e968d765 100644 --- a/types.db +++ b/types.db @@ -1549,13 +1549,16 @@ (chicken.io#read-byte (#(procedure #:enforce) chicken.io#read-byte (#!optional input-port) *)) (chicken.io#read-line (#(procedure #:enforce) chicken.io#read-line (#!optional input-port (or false fixnum)) (or eof string))) (chicken.io#read-lines (#(procedure #:enforce) chicken.io#read-lines (#!optional input-port fixnum) (list-of string))) -(chicken.io#read-string (#(procedure #:enforce) chicken.io#read-string (#!optional (or fixnum false) input-port) (or string eof))) (chicken.io#read-string! (#(procedure #:enforce) chicken.io#read-string! ((or fixnum false) string #!optional input-port fixnum) fixnum)) (chicken.io#read-token (#(procedure #:enforce) chicken.io#read-token ((procedure (char) *) #!optional input-port) string)) (chicken.io#write-byte (#(procedure #:enforce) chicken.io#write-byte (fixnum #!optional output-port) undefined)) (chicken.io#write-line (#(procedure #:enforce) chicken.io#write-line (string #!optional output-port) undefined)) (chicken.io#write-string (#(procedure #:enforce) chicken.io#write-string (string #!optional * output-port) undefined)) +(chicken.io#read-string (#(procedure #:enforce) chicken.io#read-string (#!optional (or fixnum false) input-port) (or string eof)) + (((or fixnum false)) (chicken.io#read-string/port #(1) ##sys#standard-input)) + (((or fixnum false) input-port) (chicken.io#read-string/port #(1) #(2)))) + ;; pretty-print (chicken.pretty-print#pp (#(procedure #:enforce) chicken.pretty-print#pp (* #!optional output-port) undefined)) -- 2.11.0