From 08e771eaa05fe36f400be4be4711b8df54de4eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilja=20Karta=C5=A1ov?= Date: Mon, 29 Apr 2019 09:08:18 +0200 Subject: [PATCH] Fix URI decode issue for feedback module --- components/query.c | 23 +++++++++++++++++++++++ components/query.h | 3 +++ mods/feedback.c | 16 ++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/components/query.c b/components/query.c index 8009c3c..df402bb 100644 --- a/components/query.c +++ b/components/query.c @@ -152,3 +152,26 @@ ax_query_feed(AxQuery query, const char *data, int32_t length) } +void +ax_query__decode(char *e_str) +{ + char *p = e_str, + hex[3] = {0,0,0}; + do { + switch(*e_str) { + case '%': + hex[0] = *(++e_str); + hex[1] = *(++e_str); + *p++ = (char)strtol(hex, NULL, 16); + break; + + case '+': + *p++ = ' '; + break; + + default: + *p++ = *e_str; + } + } while(*e_str++ != 0); +} + diff --git a/components/query.h b/components/query.h index 9c27886..6574adf 100644 --- a/components/query.h +++ b/components/query.h @@ -51,4 +51,7 @@ AislStatus ax_query_feed(AxQuery query, const char *data, int32_t length); +void +ax_query__decode(char *e_str); + #endif /* !QUERY_H */ diff --git a/mods/feedback.c b/mods/feedback.c index 397ff2c..1c503b6 100644 --- a/mods/feedback.c +++ b/mods/feedback.c @@ -59,17 +59,25 @@ on_input_var( const char *key, uint32_t k_len, { Context ctx = (Context) p_ctx; AxFeedback mod = (AxFeedback)((AxContext)ctx)->mod; + char **out = NULL; if (!ctx->email && k_len == mod->name_email_length) { - if (strncmp(key, mod->name_email, k_len)==0) - return (cstuff_strncpy(&ctx->email, val, v_len) == -1); + if (strncmp(key, mod->name_email, k_len) == 0) { + out = &ctx->email; + } } if (!ctx->msg && k_len == mod->name_msg_length) { - if (strncmp(key, mod->name_msg, k_len)==0) - return (cstuff_strncpy(&ctx->msg, val, v_len) == -1); + if (strncmp(key, mod->name_msg, k_len)==0) { + out = &ctx->msg; + } } + if (out) { + if (cstuff_strncpy(out, val, v_len) == -1) + return -1; + ax_query__decode(*out); + } return 0; }