Skip to content

Commit

Permalink
separate JSON parse and structure errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lyokha committed Feb 19, 2022
1 parent c46d64f commit 24d76f4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/ngx_http_custom_counters_persistency.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 24d76f4

Please sign in to comment.