summaryrefslogtreecommitdiff
path: root/src/ot_urlencoded.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_urlencoded.c')
-rw-r--r--src/ot_urlencoded.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ot_urlencoded.c b/src/ot_urlencoded.c
index 4109bb5..c977adb 100644
--- a/src/ot_urlencoded.c
+++ b/src/ot_urlencoded.c
@@ -68,17 +68,18 @@ void urlencoded_skip_value(char **string) {
68 *string = (char *)s; 68 *string = (char *)s;
69} 69}
70 70
71int urlencoded_match_keyword(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { 71int urlencoded_match_keyword(const ot_keywords *keywords, char **string, const char *deststring_end, SCAN_SEARCHPATH_FLAG flags) {
72 char *deststring = *string; 72 char *deststring = *string;
73 ssize_t match_length = urlencoded_parse(string, deststring, flags); 73 ssize_t match_length = urlencoded_parse(string, deststring, deststring_end, flags);
74 74
75 if (match_length < 0) 75 if (match_length < 0)
76 return match_length; 76 return match_length;
77 if (match_length == 0) 77 if (match_length == 0)
78 return -3; 78 return -3;
79 79
80 /* Compare on the exact decoded length. */
80 while (keywords->key) { 81 while (keywords->key) {
81 if (!strncmp(keywords->key, deststring, match_length) && !keywords->key[match_length]) 82 if ((size_t)match_length == strlen(keywords->key) && !memcmp(keywords->key, deststring, (size_t)match_length))
82 return keywords->value; 83 return keywords->value;
83 keywords++; 84 keywords++;
84 } 85 }
@@ -86,7 +87,7 @@ int urlencoded_match_keyword(const ot_keywords *keywords, char **string, SCAN_SE
86 return -3; 87 return -3;
87} 88}
88 89
89ssize_t urlencoded_parse(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { 90ssize_t urlencoded_parse(char **string, char *deststring, const char *deststring_end, SCAN_SEARCHPATH_FLAG flags) {
90 const unsigned char *s = *(const unsigned char **)string; 91 const unsigned char *s = *(const unsigned char **)string;
91 unsigned char *d = (unsigned char *)deststring; 92 unsigned char *d = (unsigned char *)deststring;
92 unsigned char b, c; 93 unsigned char b, c;
@@ -106,6 +107,9 @@ ssize_t urlencoded_parse(char **string, char *deststring, SCAN_SEARCHPATH_FLAG f
106 c |= (b << 4); 107 c |= (b << 4);
107 } 108 }
108 109
110 if ((const char *)d >= deststring_end)
111 return -1;
112
109 /* Write (possibly decoded) character to output */ 113 /* Write (possibly decoded) character to output */
110 *d++ = c; 114 *d++ = c;
111 } 115 }