Store string variables from libmaxmind in request pool
Using direct references may cause SIGSEGV on database reload (when auto_reload parameter is enabled).
This commit is contained in:
parent
26399de025
commit
80659b1bee
2 changed files with 20 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue