From 1dc87feb20fbfd7cf3fe974f7e39fd6892ebcf85 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Mar 2006 11:57:37 +0400 Subject: [PATCH] xml.result, xml.test: Adding test. item_xmlfunc.cc: Bug #18171 XML: ExtractValue: the XPath position() function crashes the server! Disallowing use of position() and last() without context. sql/item_xmlfunc.cc: Bug #18171 XML: ExtractValue: the XPath position() function crashes the server! Disallowing use of position() and last() without context. mysql-test/t/xml.test: Adding test. mysql-test/r/xml.result: Adding test. --- mysql-test/r/xml.result | 4 ++++ mysql-test/t/xml.test | 9 +++++++++ sql/item_xmlfunc.cc | 6 ++++-- 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('Jack','/a[contains(../a,"j")]' collate latin1_bin) select extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]'); extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]') +select extractValue('1','position()'); +ERROR HY000: XPATH syntax error: '' +select extractValue('1','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('Jack','/a[contains(../a,"J")]'); select extractvalue('Jack','/a[contains(../a,"j")]'); select extractvalue('Jack','/a[contains(../a,"j")]' collate latin1_bin); select extractvalue('Jack' collate latin1_bin,'/a[contains(../a,"j")]'); + +# +# Bug #18171 XML: ExtractValue: the XPath position() +# function crashes the server! +# +--error 1105 +select extractValue('1','position()'); +--error 1105 +select extractValue('1','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; }