Bug #121957 XML functions accept equal-length mismatched closing tags
Description:
ExtractValue and UpdateXML accept malformed source XML when the opening and closing element names differ but have the same byte length.
ExtractValue('<a>x</b>', '/a') returns x without a warning, and UpdateXML('<a>x</b>', '/a', '<c>y</c>') returns <c>y</c> without a warning. The same malformed value is also accepted by a prepared ExtractValue statement.
In contrast, the unequal-length mismatch <a>x</bb> is rejected correctly, returning NULL with warning 1525:
Warning 1525 Incorrect XML value: 'parse error at line 1 pos 9: '</bb>' unexpected ('</>' wanted)'
Both mismatched documents should return NULL with warning 1525.
How to repeat:
SELECT ExtractValue('<a>x</a>', '/a');
-- returns x
SELECT ExtractValue('<a>x</b>', '/a');
SHOW WARNINGS;
-- returns x without a warning; expected NULL with warning 1525
SELECT ExtractValue('<a>x</bb>', '/a');
SHOW WARNINGS;
-- returns NULL
-- Warning 1525 Incorrect XML value: 'parse error at line 1 pos 9: '</bb>' unexpected ('</>' wanted)'
-- UpdateXML variant:
SELECT UpdateXML('<a>x</b>', '/a', '<c>y</c>');
SHOW WARNINGS;
-- returns <c>y</c> without a warning; expected NULL with warning 1525
-- Prepared-statement variant:
PREPARE stmt1 FROM 'SELECT ExtractValue(?, ''/a'')';
SET @xml = '<a>x</b>';
EXECUTE stmt1 USING @xml;
SHOW WARNINGS;
-- returns x without a warning; expected NULL with warning 1525
DEALLOCATE PREPARE stmt1;
Suggested fix:
When processing a closing tag, compare the closing element name with the pending opening element name, not only their lengths.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.047 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: ExtractValue and UpdateXML accept malformed source XML when the opening and closing element names differ but have the same byte length. ExtractValue('<a>x</b>', '/a') returns x without a warning, and UpdateXML('<a>x</b>', '/a', '<c>y</c>') returns <c>y</c> without a warning. The same malformed value is also accepted by a prepared ExtractValue statement. In contrast, the unequal-length mismatch <a>x</bb> is rejected correctly, returning NULL with warning 1525: Warning 1525 Incorrect XML value: 'parse error at line 1 pos 9: '</bb>' unexpected ('</>' wanted)' Both mismatched documents should return NULL with warning 1525. How to repeat: SELECT ExtractValue('<a>x</a>', '/a'); -- returns x SELECT ExtractValue('<a>x</b>', '/a'); SHOW WARNINGS; -- returns x without a warning; expected NULL with warning 1525 SELECT ExtractValue('<a>x</bb>', '/a'); SHOW WARNINGS; -- returns NULL -- Warning 1525 Incorrect XML value: 'parse error at line 1 pos 9: '</bb>' unexpected ('</>' wanted)' -- UpdateXML variant: SELECT UpdateXML('<a>x</b>', '/a', '<c>y</c>'); SHOW WARNINGS; -- returns <c>y</c> without a warning; expected NULL with warning 1525 -- Prepared-statement variant: PREPARE stmt1 FROM 'SELECT ExtractValue(?, ''/a'')'; SET @xml = '<a>x</b>'; EXECUTE stmt1 USING @xml; SHOW WARNINGS; -- returns x without a warning; expected NULL with warning 1525 DEALLOCATE PREPARE stmt1; Suggested fix: When processing a closing tag, compare the closing element name with the pending opening element name, not only their lengths.