Skip to content

Commit a4dd37f

Browse files
Adriano Ferreirakimchy
authored andcommitted
Make RestUtils.decodeQueryString() more robust in edge cases
The code of decodeQueryString() had some trouble with weird URLs: (1) an input like "uri?param&p=v" causes an exception to be thrown (2) an input like "uri?param1&param2" causes an infinite loop This could be verified against an ES server with requests like curl -XGET localhost:9200/test/_analyze?t&text=this+is+a+test # the exception stack trace shows up in logs curl -XGET localhost:9200/test/_analyze?t1&t2&text=this+is+a+test # never returns, never ends This change fixes these issues.
1 parent c7debc0 commit a4dd37f

File tree

1 file changed

+2
-3
lines changed
  • modules/elasticsearch/src/main/java/org/elasticsearch/rest/support

1 file changed

+2
-3
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public static void decodeQueryString(String queryString, int fromIndex, Map<Stri
3939
int toIndex;
4040
while ((toIndex = queryString.indexOf('&', fromIndex)) >= 0) {
4141
int idx = queryString.indexOf('=', fromIndex);
42-
if (idx < 0) {
43-
continue;
42+
if (fromIndex < idx && idx < toIndex) {
43+
params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex)));
4444
}
45-
params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex)));
4645
fromIndex = toIndex + 1;
4746
}
4847
int idx = queryString.indexOf('=', fromIndex);

0 commit comments

Comments
 (0)