Skip to content

Commit

Permalink
Store string variables from libmaxmind in request pool
Browse files Browse the repository at this point in the history
Using direct references may cause SIGSEGV on database reload
(when auto_reload parameter is enabled).
  • Loading branch information
defanator committed Oct 11, 2018
1 parent 26399de commit 80659b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions ngx_http_geoip2_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,20 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
FORMAT("%d", entry_data.boolean);
break;
case MMDB_DATA_TYPE_UTF8_STRING:
v->data = (u_char *) entry_data.utf8_string;
v->len = entry_data.data_size;
v->data = ngx_pnalloc(r->pool, v->len);
if (v->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(v->data, (u_char *) entry_data.utf8_string, v->len);
break;
case MMDB_DATA_TYPE_BYTES:
v->data = (u_char *) entry_data.bytes;
v->len = entry_data.data_size;
v->data = ngx_pnalloc(r->pool, v->len);
if (v->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(v->data, (u_char *) entry_data.bytes, v->len);
break;
case MMDB_DATA_TYPE_FLOAT:
FORMAT("%.5f", entry_data.float_value);
Expand Down
12 changes: 10 additions & 2 deletions ngx_stream_geoip2_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,20 @@ ngx_stream_geoip2_variable(ngx_stream_session_t *s, ngx_stream_variable_value_t
FORMAT("%d", entry_data.boolean);
break;
case MMDB_DATA_TYPE_UTF8_STRING:
v->data = (u_char *) entry_data.utf8_string;
v->len = entry_data.data_size;
v->data = ngx_pnalloc(r->pool, v->len);
if (v->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(v->data, (u_char *) entry_data.utf8_string, v->len);
break;
case MMDB_DATA_TYPE_BYTES:
v->data = (u_char *) entry_data.bytes;
v->len = entry_data.data_size;
v->data = ngx_pnalloc(r->pool, v->len);
if (v->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(v->data, (u_char *) entry_data.bytes, v->len);
break;
case MMDB_DATA_TYPE_FLOAT:
FORMAT("%.5f", entry_data.float_value);
Expand Down

0 comments on commit 80659b1

Please sign in to comment.