From e0bab441a86f888d5db1be90756c56804f5dbb05 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 25 Jul 2013 20:39:57 -0600 Subject: [PATCH] fix `get-output-{bytes,string}' with bad starting index, no ending index Closes PR 13933 --- pkgs/racket-pkgs/racket-test/tests/racket/file.rktl | 5 +++++ racket/src/racket/src/portfun.c | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkgs/racket-pkgs/racket-test/tests/racket/file.rktl b/pkgs/racket-pkgs/racket-test/tests/racket/file.rktl index 72a83359fd..d878f05405 100644 --- a/pkgs/racket-pkgs/racket-test/tests/racket/file.rktl +++ b/pkgs/racket-pkgs/racket-test/tests/racket/file.rktl @@ -211,6 +211,11 @@ (test #"23" get-output-bytes os #t 1 3) (test #"" get-output-bytes os #f 0 #f)) +(err/rt-test (get-output-bytes (open-output-bytes) #t 1)) +(err/rt-test (get-output-bytes (open-output-bytes) #t 0 1)) +(err/rt-test (get-output-bytes (open-output-string) #t 1)) +(err/rt-test (get-output-bytes (open-output-string) #t 0 1)) + (define s (open-output-string)) (err/rt-test (file-position 's 1)) (err/rt-test (file-position s 'one)) diff --git a/racket/src/racket/src/portfun.c b/racket/src/racket/src/portfun.c index e2d440c657..58aa8972e6 100644 --- a/racket/src/racket/src/portfun.c +++ b/racket/src/racket/src/portfun.c @@ -2648,7 +2648,7 @@ Scheme_Object *do_get_output_string(const char *who, int is_byte, if (endpos < 0) endpos = len+1; } - + if (!(startpos <= len)) { scheme_out_of_range(who, "port", "starting ", argv[2], argv[0], 0, len); return NULL; @@ -2657,8 +2657,13 @@ Scheme_Object *do_get_output_string(const char *who, int is_byte, scheme_out_of_range(who, "port", "ending ", argv[3], argv[0], startpos, len); return NULL; } - } else + } else { + if (!(startpos <= len)) { + scheme_out_of_range(who, "port", "starting ", argv[2], argv[0], 0, len); + return NULL; + } endpos = -1; + } } else { startpos = 0; endpos = -1;