summaryrefslogtreecommitdiff
path: root/ext/syck
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-19 16:38:02 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-19 16:38:02 +0000
commit360b0a015aba72f62ea2ffee4f52ce2b9132a2d1 (patch)
treed9ea3de53d9d04bd0234fd061fdcfda9e57910ec /ext/syck
parent94c2e6f18a7e3146802ebc5c08b4cbec627143f5 (diff)
* ext/syck/syck.h: Parser definition problems on HP-UX. [ruby-talk:79389]
* ext/syck/handler.c (syck_hdlr_get_anchor): Memory leak. * ext/syck/syck.s (syck_io_file_read): Bad arguments to fread. * ext/syck/rubyext.c: Tainting issues. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck')
-rw-r--r--ext/syck/handler.c14
-rw-r--r--ext/syck/rubyext.c44
-rw-r--r--ext/syck/syck.c4
-rw-r--r--ext/syck/syck.h40
4 files changed, 53 insertions, 49 deletions
diff --git a/ext/syck/handler.c b/ext/syck/handler.c
index 0a7ee8c..ca15fd0 100644
--- a/ext/syck/handler.c
+++ b/ext/syck/handler.c
@@ -1,5 +1,5 @@
/*
- * handler.h
+ * handler.c
*
* $Author$
* $Date$
@@ -73,6 +73,7 @@ syck_hdlr_get_anchor( SyckParser *p, char *a )
{
if ( n != (void *)1 )
{
+ S_FREE( a );
return n;
}
else
@@ -94,7 +95,16 @@ syck_hdlr_get_anchor( SyckParser *p, char *a )
{
n = (p->bad_anchor_handler)( p, a );
}
- n->anchor = a;
+
+ if ( n->anchor )
+ {
+ S_FREE( a );
+ }
+ else
+ {
+ n->anchor = a;
+ }
+
return n;
}
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 1e6030b..ec54ef8 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -68,6 +68,7 @@ void rb_syck_output_handler _((SyckEmitter *, char *, long));
struct parser_xtra {
VALUE data; /* Borrowed this idea from marshal.c to fix [ruby-core:8067] problem */
VALUE proc;
+ int taint;
};
/*
@@ -103,31 +104,29 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
/*
* determine: are we reading from a string or io?
+ * (returns tainted? boolean)
*/
-void
+int
syck_parser_assign_io(parser, port)
SyckParser *parser;
VALUE port;
{
+ int taint = Qtrue;
if (rb_respond_to(port, rb_intern("to_str"))) {
-#if 0
- arg.taint = OBJ_TAINTED(port); /* original taintedness */
+ taint = OBJ_TAINTED(port); /* original taintedness */
StringValue(port); /* possible conversion */
-#endif
syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
}
else if (rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
}
-#if 0
- arg.taint = Qfalse;
-#endif
syck_parser_str( parser, (char *)port, 0, rb_syck_io_str_read );
}
else {
rb_raise(rb_eTypeError, "instance of IO needed");
}
+ return taint;
}
/*
@@ -283,10 +282,8 @@ rb_syck_parse_handler(p, n)
}
bonus = (struct parser_xtra *)p->bonus;
- if ( bonus->proc != 0 )
- {
- rb_funcall(bonus->proc, s_call, 1, v);
- }
+ if ( bonus->taint) OBJ_TAINT( obj );
+ if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, v);
rb_iv_set(obj, "@value", v);
rb_hash_aset(bonus->data, INT2FIX(RHASH(bonus->data)->tbl->num_entries), obj);
@@ -481,10 +478,8 @@ rb_syck_load_handler(p, n)
}
bonus = (struct parser_xtra *)p->bonus;
- if ( bonus->proc != 0 )
- {
- rb_funcall(bonus->proc, s_call, 1, obj);
- }
+ if ( bonus->taint) OBJ_TAINT( obj );
+ if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj);
if ( check_transfers == 1 && n->type_id != NULL )
{
@@ -617,11 +612,11 @@ syck_parser_load(argc, argv, self)
rb_scan_args(argc, argv, "11", &port, &proc);
Data_Get_Struct(self, SyckParser, parser);
- syck_parser_assign_io(parser, port);
model = rb_hash_aref( rb_iv_get( self, "@options" ), sym_model );
syck_set_model( parser, model );
+ bonus.taint = syck_parser_assign_io(parser, port);
bonus.data = hash = rb_hash_new();
if ( NIL_P( proc ) ) bonus.proc = 0;
else bonus.proc = proc;
@@ -647,11 +642,11 @@ syck_parser_load_documents(argc, argv, self)
rb_scan_args(argc, argv, "1&", &port, &proc);
Data_Get_Struct(self, SyckParser, parser);
- syck_parser_assign_io(parser, port);
model = rb_hash_aref( rb_iv_get( self, "@options" ), sym_model );
syck_set_model( parser, model );
+ bonus.taint = syck_parser_assign_io(parser, port);
while ( 1 )
{
/* Reset hash for tracking nodes */
@@ -822,10 +817,6 @@ syck_loader_transfer( self, type, val )
{
char *taguri = NULL;
-#if 0
- rb_p(rb_str_new2( "-- TYPE --" ));
- rb_p(type);
-#endif
if (NIL_P(type) || !RSTRING(type)->ptr || RSTRING(type)->len == 0)
{
/*
@@ -849,9 +840,6 @@ syck_loader_transfer( self, type, val )
VALUE str_taguri = rb_str_new2("taguri");
VALUE str_xprivate = rb_str_new2("x-private");
VALUE parts = rb_str_split( type_uri, ":" );
-#if 0
- rb_p(parts);
-#endif
scheme = rb_ary_shift( parts );
@@ -884,10 +872,6 @@ syck_loader_transfer( self, type, val )
name = rb_ary_shift( col );
type_proc = rb_ary_shift( col );
}
-#if 0
- rb_p(name);
- rb_p(type_proc);
-#endif
}
if ( rb_respond_to( type_proc, s_call ) )
@@ -1108,7 +1092,7 @@ syck_emitter_write_m( self, str )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
syck_emitter_write( emitter, RSTRING(str)->ptr, RSTRING(str)->len );
return self;
}
@@ -1122,7 +1106,7 @@ syck_emitter_simple_write( self, str )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
syck_emitter_simple( emitter, RSTRING(str)->ptr, RSTRING(str)->len );
return self;
}
diff --git a/ext/syck/syck.c b/ext/syck/syck.c
index 42b7057..7072257 100644
--- a/ext/syck/syck.c
+++ b/ext/syck/syck.c
@@ -50,7 +50,7 @@ syck_io_file_read( char *buf, SyckIoFile *file, long max_size, long skip )
ASSERT( file != NULL );
max_size -= skip;
- len = fread( buf + skip, max_size, sizeof( char ), file->ptr );
+ len = fread( buf + skip, sizeof( char ), max_size, file->ptr );
len += skip;
buf[len] = '\0';
@@ -181,7 +181,7 @@ syck_add_sym( SyckParser *p, char *data )
{
p->syms = st_init_numtable();
}
- id = p->syms->num_entries;
+ id = p->syms->num_entries + 1;
st_insert( p->syms, id, (st_data_t)data );
return id;
}
diff --git a/ext/syck/syck.h b/ext/syck/syck.h
index 124e6c5..49efd35 100644
--- a/ext/syck/syck.h
+++ b/ext/syck/syck.h
@@ -13,7 +13,7 @@
#define SYCK_YAML_MAJOR 1
#define SYCK_YAML_MINOR 0
-#define SYCK_VERSION "0.38"
+#define SYCK_VERSION "0.39"
#define YAML_DOMAIN "yaml.org,2002"
#include <stdio.h>
@@ -152,8 +152,28 @@ enum syck_level_status {
};
/*
- * Parser struct
+ * Parser structs
*/
+struct _syck_file {
+ /* File pointer */
+ FILE *ptr;
+ /* Function which FILE -> buffer */
+ SyckIoFileRead read;
+};
+
+struct _syck_str {
+ /* String buffer pointers */
+ char *beg, *ptr, *end;
+ /* Function which string -> buffer */
+ SyckIoStrRead read;
+};
+
+struct _syck_level {
+ int spaces;
+ char *domain;
+ enum syck_level_status status;
+};
+
struct _syck_parser {
/* Root node */
SYMID root, root_on_error;
@@ -180,25 +200,15 @@ struct _syck_parser {
/* EOF flag */
int eof;
union {
- struct _syck_file {
- FILE *ptr;
- SyckIoFileRead read;
- } *file;
- struct _syck_str {
- char *beg, *ptr, *end;
- SyckIoStrRead read;
- } *str;
+ SyckIoFile *file;
+ SyckIoStr *str;
} io;
/* Symbol table for anchors */
st_table *anchors, *bad_anchors;
/* Optional symbol table for SYMIDs */
st_table *syms;
/* Levels of indentation */
- struct _syck_level {
- int spaces;
- char *domain;
- enum syck_level_status status;
- } *levels;
+ SyckLevel *levels;
int lvl_idx;
int lvl_capa;
void *bonus;