summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/xml.result4
-rw-r--r--mysql-test/t/xml.test9
-rw-r--r--sql/item_xmlfunc.cc6
3 files changed, 17 insertions, 2 deletions
diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result
index bb7a158593c..d213ef98885 100644
--- a/mysql-test/r/xml.result
+++ b/mysql-test/r/xml.result
@@ -609,3 +609,7 @@ extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin)
select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]');
extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]')
+select extractValue('<e>1</e>','position()');
+ERROR HY000: XPATH syntax error: ''
+select extractValue('<e>1</e>','last()');
+ERROR HY000: XPATH syntax error: ''
diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test
index 831867937e4..ae1c9cf3b6b 100644
--- a/mysql-test/t/xml.test
+++ b/mysql-test/t/xml.test
@@ -277,3 +277,12 @@ select extractvalue('<a>Jack</a>','/a[contains(../a,"J")]');
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]');
select extractvalue('<a>Jack</a>','/a[contains(../a,"j")]' collate latin1_bin);
select extractvalue('<a>Jack</a>' collate latin1_bin,'/a[contains(../a,"j")]');
+
+#
+# Bug #18171 XML: ExtractValue: the XPath position()
+# function crashes the server!
+#
+--error 1105
+select extractValue('<e>1</e>','position()');
+--error 1105
+select extractValue('<e>1</e>','last()');
diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc
index 7378be0ac4c..da39c1e4409 100644
--- a/sql/item_xmlfunc.cc
+++ b/sql/item_xmlfunc.cc
@@ -1141,13 +1141,15 @@ static Item *create_func_round(MY_XPATH *xpath, Item **args, uint nargs)
static Item *create_func_last(MY_XPATH *xpath, Item **args, uint nargs)
{
- return new Item_func_xpath_count(xpath->context, xpath->pxml);
+ return xpath->context ?
+ new Item_func_xpath_count(xpath->context, xpath->pxml) : NULL;
}
static Item *create_func_position(MY_XPATH *xpath, Item **args, uint nargs)
{
- return new Item_func_xpath_position(xpath->context, xpath->pxml);
+ return xpath->context ?
+ new Item_func_xpath_position(xpath->context, xpath->pxml) : NULL;
}