Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ISeq#compile should accept IOs (like Ripper does today) #136

Closed
wants to merge 2 commits into from

3 participants

@drbrain
Collaborator

What about StringIO?

@shyouhei
Owner

Yes, that would be nice... The problem is however, that an IO-like object such as StringIO can break ISeq compilation by cheating #gets method. I wish we could stop rerouting gets method to another (potentially malicious) one.

@zzak
Collaborator

Closing this, please refer to Feature #2674 in redmine

@zzak zzak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 2 deletions.
  1. +9 −1 iseq.c
  2. +3 −1 parse.y
View
10 iseq.c
@@ -580,11 +580,19 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE li
if ((state = EXEC_TAG()) == 0) {
int ln = NUM2INT(line);
const char *fn = StringValueCStr(file);
- NODE *node = parse_string(StringValue(src), fn, ln);
+ NODE *node;
rb_compile_option_t option;
make_compile_option(&option, opt);
+ if (BUILTIN_TYPE(src) == T_FILE)
+ node = rb_compile_file(fn, src, ln);
+ else
+ node = parse_string(StringValue(src), fn, ln);
+
+ if (!node)
+ rb_exc_raise(GET_THREAD()->errinfo);
+
if (base_block && base_block->iseq) {
iseqval = rb_iseq_new_with_opt(node, base_block->iseq->location.label,
file, absolute_path, line, base_block->iseq->self,
View
4 parse.y
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
+#include <assert.h>
#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
@@ -5494,6 +5495,7 @@ rb_compile_file(const char *f, VALUE file, int start)
{
VALUE volatile vparser = rb_parser_new();
+ assert(BUILTIN_TYPE(file) == T_FILE); /* Not sure if we can call rb_raise() here. */
return rb_parser_compile_file(vparser, f, file, start);
}
@@ -11089,7 +11091,7 @@ ripper_initialize(int argc, VALUE *argv, VALUE self)
TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
- if (rb_obj_respond_to(src, ripper_id_gets, 0)) {
+ if (BUILTIN_TYPE(src) == T_FILE) {
parser->parser_lex_gets = ripper_lex_get_generic;
}
else {
Something went wrong with that request. Please try again.