diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-08-29 16:11:52 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-08-29 16:11:52 -0700 |
commit | ed276bd6ba03b89201bfdfd1730b428b224372f0 (patch) | |
tree | 4c9489303341b10e5372f116e6b0d20293a21c73 /ext | |
parent | e4bdbdcfcbf51ee91e4192ef361ba73e80e14dcc (diff) | |
download | clogger-ed276bd6ba03b89201bfdfd1730b428b224372f0.tar.gz |
Add a little more tolerance for bad applications that may not give us string objects. This should only have a minor performance penalty for proper applications but at least ensures we don't segfault on misbehaving apps.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/clogger_ext/clogger.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 3c6d25a..de38ba2 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -188,7 +188,7 @@ struct response_ops { long nr; VALUE ops; }; static VALUE swap_sent_headers(VALUE kv, VALUE memo) { struct response_ops *tmp = (struct response_ops *)memo; - VALUE key = RARRAY_PTR(kv)[0]; + VALUE key = rb_obj_as_string(RARRAY_PTR(kv)[0]); long i = RARRAY_LEN(tmp->ops); VALUE *ary = RARRAY_PTR(tmp->ops); VALUE value; @@ -337,10 +337,11 @@ static VALUE clogger_wrap_body(VALUE self) return clogger_get(self)->wrap_body == 0 ? Qfalse : Qtrue; } -static void append_status(struct clogger *c, VALUE status) +static void append_status(struct clogger *c) { char buf[sizeof("999")]; int nr; + VALUE status = RARRAY_PTR(c->response)[0]; if (TYPE(status) != T_FIXNUM) { status = rb_funcall(status, to_i_id, 0); @@ -542,7 +543,7 @@ static void special_var(struct clogger *c, enum clogger_special var) append_body_bytes_sent(c); break; case CL_SP_status: - append_status(c, RARRAY_PTR(c->response)[0]); + append_status(c); break; case CL_SP_request: append_request(c); @@ -673,6 +674,7 @@ static VALUE body_iter_i(VALUE str, VALUE memop) { off_t *len = (off_t *)memop; + str = rb_obj_as_string(str); *len += RSTRING_LEN(str); return rb_yield(str); @@ -682,7 +684,6 @@ static VALUE wrap_each(struct clogger *c) { VALUE body = RARRAY_PTR(c->response)[2]; - rb_need_block(); c->body_bytes_sent = 0; rb_iterate(rb_each, body, body_iter_i, (VALUE)&c->body_bytes_sent); @@ -701,6 +702,8 @@ static VALUE clogger_each(VALUE self) { struct clogger *c = clogger_get(self); + rb_need_block(); + return rb_ensure(wrap_each, (VALUE)c, cwrite, (VALUE)c); } |