From 64be8717bdc2f0f8f11cbb8d18a0f96d2c24c6d3 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 16 Sep 2019 20:17:42 +0300 Subject: Configuration: added ability to access object members with slashes. Now URI encoding can be used to escape "/" in the request path: GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/ --- src/nxt_conf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nxt_conf.c') diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 57870838..ff82e1d2 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -416,10 +416,13 @@ static void nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, nxt_conf_value_t * nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path) { + u_char *end; nxt_str_t token; nxt_int_t index; nxt_conf_path_parse_t parse; + u_char buf[256]; + parse.start = path->start; parse.end = path->start + path->length; parse.last = 0; @@ -436,6 +439,18 @@ nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path) return NULL; } + if (nxt_slow_path(token.length > 256)) { + return NULL; + } + + end = nxt_decode_uri(buf, token.start, token.length); + if (nxt_slow_path(end == NULL)) { + return NULL; + } + + token.length = end - buf; + token.start = buf; + switch (value->type) { case NXT_CONF_VALUE_OBJECT: -- cgit From ca01845d89968ef8b726f8e4a683a06c518755e4 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 18 Sep 2019 16:03:28 +0300 Subject: Configuration: added ability to modify object members with slashes. Example: PUT/POST/DELETE /config/listeners/unix:%2Fpath%2Fto%2Fsocket This follows a49ee872e83d. --- src/nxt_conf.c | 88 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 39 deletions(-) (limited to 'src/nxt_conf.c') diff --git a/src/nxt_conf.c b/src/nxt_conf.c index ff82e1d2..59eddd77 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -16,6 +16,8 @@ #define NXT_CONF_MAX_SHORT_STRING 14 #define NXT_CONF_MAX_STRING NXT_INT32_T_MAX +#define NXT_CONF_MAX_TOKEN_LEN 256 + typedef enum { NXT_CONF_VALUE_NULL = 0, @@ -90,6 +92,17 @@ struct nxt_conf_op_s { }; +typedef struct { + u_char *start; + u_char *end; + nxt_bool_t last; + u_char buf[NXT_CONF_MAX_TOKEN_LEN]; +} nxt_conf_path_parse_t; + + +static nxt_int_t nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, + nxt_str_t *token); + static u_char *nxt_conf_json_skip_space(u_char *start, u_char *end); static u_char *nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, u_char *end, nxt_conf_json_error_t *error); @@ -402,33 +415,22 @@ nxt_conf_type(nxt_conf_value_t *value) } -typedef struct { - u_char *start; - u_char *end; - nxt_bool_t last; -} nxt_conf_path_parse_t; - - -static void nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, - nxt_str_t *token); - - nxt_conf_value_t * nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path) { - u_char *end; nxt_str_t token; - nxt_int_t index; + nxt_int_t ret, index; nxt_conf_path_parse_t parse; - u_char buf[256]; - parse.start = path->start; parse.end = path->start + path->length; parse.last = 0; do { - nxt_conf_path_next_token(&parse, &token); + ret = nxt_conf_path_next_token(&parse, &token); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } if (token.length == 0) { @@ -439,18 +441,6 @@ nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path) return NULL; } - if (nxt_slow_path(token.length > 256)) { - return NULL; - } - - end = nxt_decode_uri(buf, token.start, token.length); - if (nxt_slow_path(end == NULL)) { - return NULL; - } - - token.length = end - buf; - token.start = buf; - switch (value->type) { case NXT_CONF_VALUE_OBJECT: @@ -481,24 +471,38 @@ nxt_conf_get_path(nxt_conf_value_t *value, nxt_str_t *path) } -static void +static nxt_int_t nxt_conf_path_next_token(nxt_conf_path_parse_t *parse, nxt_str_t *token) { - u_char *p, *end; + u_char *p, *start, *end; + size_t length; - end = parse->end; - p = parse->start + 1; + start = parse->start + 1; - token->start = p; + p = start; - while (p < end && *p != '/') { + while (p < parse->end && *p != '/') { p++; } parse->start = p; - parse->last = (p >= end); + parse->last = (p >= parse->end); + + length = p - start; + + if (nxt_slow_path(length > NXT_CONF_MAX_TOKEN_LEN)) { + return NXT_ERROR; + } + + end = nxt_decode_uri(parse->buf, start, length); + if (nxt_slow_path(end == NULL)) { + return NXT_ERROR; + } + + token->length = end - parse->buf; + token->start = parse->buf; - token->length = p - token->start; + return NXT_OK; } @@ -757,7 +761,7 @@ nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops, nxt_conf_value_t *root, nxt_str_t *path, nxt_conf_value_t *value, nxt_bool_t add) { nxt_str_t token; - nxt_int_t index; + nxt_int_t ret, index; nxt_conf_op_t *op, **parent; nxt_conf_value_t *node; nxt_conf_path_parse_t parse; @@ -778,7 +782,10 @@ nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops, nxt_conf_value_t *root, *parent = op; parent = (nxt_conf_op_t **) &op->ctx; - nxt_conf_path_next_token(&parse, &token); + ret = nxt_conf_path_next_token(&parse, &token); + if (nxt_slow_path(ret != NXT_OK)) { + return NXT_CONF_OP_ERROR; + } switch (root->type) { @@ -872,7 +879,10 @@ nxt_conf_op_compile(nxt_mp_t *mp, nxt_conf_op_t **ops, nxt_conf_value_t *root, return NXT_CONF_OP_ERROR; } - nxt_conf_set_string(&member->name, &token); + ret = nxt_conf_set_string_dup(&member->name, mp, &token); + if (nxt_slow_path(ret != NXT_OK)) { + return NXT_CONF_OP_ERROR; + } member->value = *value; -- cgit