From 154dcf007e655cd9637ebfac7e2af5af09b15b7c Mon Sep 17 00:00:00 2001 From: Adriano Ferreira Date: Thu, 6 Jan 2011 18:59:56 -0200 Subject: [PATCH] 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¶m2" 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. --- .../main/java/org/elasticsearch/rest/support/RestUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java index 028465eaa43..375c702900e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java @@ -39,10 +39,9 @@ public class RestUtils { int toIndex; while ((toIndex = queryString.indexOf('&', fromIndex)) >= 0) { int idx = queryString.indexOf('=', fromIndex); - if (idx < 0) { - continue; + if (fromIndex < idx && idx < toIndex) { + params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex))); } - params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex))); fromIndex = toIndex + 1; } int idx = queryString.indexOf('=', fromIndex);