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:
Andrei Belov 2018-10-11 16:59:37 +03:00
parent 26399de025
commit 80659b1bee
No known key found for this signature in database
GPG key ID: 1465F6CF06C1F0CD
2 changed files with 20 additions and 4 deletions

View file

@ -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);

View file

@ -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);