Skip to content

Commit

Permalink
Use RSTRING_LEN() instead of as.heap.ptr to fix SIGSEGV. Fixed matsum…
Browse files Browse the repository at this point in the history
  • Loading branch information
yyamano committed Dec 5, 2016
1 parent 7ca17f6 commit 1439a44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
14 changes: 2 additions & 12 deletions src/http/ngx_http_mruby_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,17 @@ void ngx_mrb_raise_error(mrb_state *mrb, mrb_value obj, ngx_http_request_t *r)

void ngx_mrb_raise_cycle_error(mrb_state *mrb, mrb_value obj, ngx_cycle_t *cycle)
{
struct RString *str;
char *err_out;

obj = mrb_funcall(mrb, obj, "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_log_error(NGX_LOG_ERR, cycle->log, 0, "mrb_run failed. error: %s", err_out);
ngx_log_error(NGX_LOG_ERR, cycle->log, 0, "mrb_run failed. error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
}

void ngx_mrb_raise_conf_error(mrb_state *mrb, mrb_value obj, ngx_conf_t *cf)
{
struct RString *str;
char *err_out;

obj = mrb_funcall(mrb, obj, "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "mrb_run failed. error: %s", err_out);
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "mrb_run failed. error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/http/ngx_http_mruby_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2541,14 +2541,10 @@ static int ngx_http_mruby_ssl_cert_handler(ngx_ssl_conn_t *ssl_conn, void *data)
}

if (mrb->exc) {
struct RString *str;
char *err_out;
mrb_value obj = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_log_error(NGX_LOG_ERR, c->log, 0,
MODULE_NAME " : mrb_run failed: return 500 HTTP status code to client: error: %s", err_out);
MODULE_NAME " : mrb_run failed: return 500 HTTP status code to client: error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(mrb, mscf->ssl_handshake_code);
NGX_MRUBY_CODE_MRBC_CONTEXT_FREE(mrb, mscf->ssl_handshake_inline_code);
Expand Down
21 changes: 3 additions & 18 deletions src/stream/ngx_stream_mruby_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,17 @@ static char *ngx_stream_mruby_merge_srv_conf(ngx_conf_t *cf, void *parent, void
/* raise functions */
static void ngx_stream_mruby_raise_error(mrb_state *mrb, mrb_value obj, ngx_stream_session_t *s)
{
struct RString *str;
char *err_out;

obj = mrb_funcall(mrb, obj, "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "mrb_run failed: return NGX_ABORT to client: error: %s", err_out);
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "mrb_run failed: return NGX_ABORT to client: error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
}

static void ngx_stream_mrb_raise_cycle_error(mrb_state *mrb, mrb_value obj, ngx_cycle_t *cycle)
{
struct RString *str;
char *err_out;

obj = mrb_funcall(mrb, obj, "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_log_error(NGX_LOG_ERR, cycle->log, 0, "mrb_run failed. error: %s", err_out);
ngx_log_error(NGX_LOG_ERR, cycle->log, 0, "mrb_run failed. error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
}

Expand Down Expand Up @@ -641,14 +631,9 @@ static char *ngx_stream_mruby_build_code(ngx_conf_t *cf, ngx_command_t *cmd, voi
/*
static void ngx_stream_mrb_raise_conf_error(mrb_state *mrb, mrb_value obj, ngx_conf_t *cf)
{
struct RString *str;
char *err_out;
obj = mrb_funcall(mrb, obj, "inspect", 0);
if (mrb_type(obj) == MRB_TT_STRING) {
str = mrb_str_ptr(obj);
err_out = str->as.heap.ptr;
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "mrb_run failed. error: %s", err_out);
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "mrb_run failed. error: %*s", RSTRING_LEN(obj), RSTRING_PTR(obj));
}
}
Expand Down

0 comments on commit 1439a44

Please sign in to comment.