diff --git a/src/ngx_http_custom_counters_persistency.c b/src/ngx_http_custom_counters_persistency.c index 4c84e2e..7f18957 100644 --- a/src/ngx_http_custom_counters_persistency.c +++ b/src/ngx_http_custom_counters_persistency.c @@ -293,11 +293,17 @@ ngx_http_cnt_counters_persistent_storage(ngx_conf_t *cf, ngx_command_t *cmd, jsmn_init(&jparse); jrc = jsmn_parse(&jparse, (char *) buf, file_size, jtok, jsz); - if (jrc < 0 || jtok[0].type != JSMN_OBJECT) { + if (jrc < 0) { ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "JSON parse error: %d", jrc); break; } + if (jtok[0].type != JSMN_OBJECT) { + ngx_conf_log_error(NGX_LOG_ERR, cf, 0, + "unexpected structure of JSON data: " + "the whole data is not an object"); + break; + } copy_backup_started = 1; @@ -432,13 +438,22 @@ ngx_http_cnt_counters_persistent_storage(ngx_conf_t *cf, ngx_command_t *cmd, jsmn_init(&jparse); jrc = jsmn_parse(&jparse, (char *) buf, file_size, jtok, jsz); - if (jrc < 0 || jtok[0].type != JSMN_OBJECT) { + if (jrc < 0) { ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "JSON parse error: %d", jrc); ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "file \"%V\" is corrupted, delete it and run again", &file.name); return NGX_CONF_ERROR; } + if (jtok[0].type != JSMN_OBJECT) { + ngx_conf_log_error(NGX_LOG_ERR, cf, 0, + "unexpected structure of JSON data: " + "the whole data is not an object"); + ngx_conf_log_error(NGX_LOG_ERR, cf, 0, + "file \"%V\" is corrupted, delete it and run again", + &file.name); + return NGX_CONF_ERROR; + } mcf->persistent_collection.len = file_size; mcf->persistent_collection.data = buf;