Ensure that database structures are zero-initialized

This should fix #58.
This commit is contained in:
Andrei Belov 2018-10-01 15:30:11 +03:00
parent d6e529a9ab
commit 38cea8a516
No known key found for this signature in database
GPG key ID: 1465F6CF06C1F0CD
2 changed files with 4 additions and 12 deletions

View file

@ -426,6 +426,8 @@ ngx_http_geoip2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
ngx_memzero(database, sizeof(ngx_http_geoip2_db_t));
database->last_check = database->last_change = ngx_time(); database->last_check = database->last_change = ngx_time();
status = MMDB_open((char *) value[1].data, MMDB_MODE_MMAP, &database->mmdb); status = MMDB_open((char *) value[1].data, MMDB_MODE_MMAP, &database->mmdb);
@ -437,12 +439,6 @@ ngx_http_geoip2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
#if (NGX_HAVE_INET6)
ngx_memset(&database->address, 0, sizeof(database->address));
#else
database->address = 0;
#endif
save = *cf; save = *cf;
cf->handler = ngx_http_geoip2_parse_config; cf->handler = ngx_http_geoip2_parse_config;
cf->handler_conf = (void *) database; cf->handler_conf = (void *) database;

View file

@ -395,6 +395,8 @@ ngx_stream_geoip2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
ngx_memzero(database, sizeof(ngx_stream_geoip2_db_t));
database->last_check = database->last_change = ngx_time(); database->last_check = database->last_change = ngx_time();
status = MMDB_open((char *) value[1].data, MMDB_MODE_MMAP, &database->mmdb); status = MMDB_open((char *) value[1].data, MMDB_MODE_MMAP, &database->mmdb);
@ -406,12 +408,6 @@ ngx_stream_geoip2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
#if (NGX_HAVE_INET6)
ngx_memset(&database->address, 0, sizeof(database->address));
#else
database->address = 0;
#endif
save = *cf; save = *cf;
cf->handler = ngx_stream_geoip2_parse_config; cf->handler = ngx_stream_geoip2_parse_config;
cf->handler_conf = (void *) database; cf->handler_conf = (void *) database;