11/*
22 * ModSecurity, http://www.modsecurity.org/
3- * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
3+ * Copyright (c) 2015 - 2023 Trustwave Holdings, Inc. (http://www.trustwave.com/)
44 *
55 * You may not use this file except in compliance with
66 * the License. You may obtain a copy of the License at
@@ -43,25 +43,24 @@ bool ValidateDTD::init(const std::string &file, std::string *error) {
4343}
4444
4545
46- bool ValidateDTD::evaluate (Transaction *t, const std::string &str) {
47- xmlValidCtxtPtr cvp;
46+ bool ValidateDTD::evaluate (Transaction *transaction, const std::string &str) {
4847
49- m_dtd = xmlParseDTD (NULL , (const xmlChar *)m_resource.c_str ());
50- if (m_dtd == NULL ) {
48+ XmlDtdPtrManager dtd ( xmlParseDTD (NULL , (const xmlChar *)m_resource.c_str () ));
49+ if (dtd. get () == NULL ) {
5150 std::string err = std::string (" XML: Failed to load DTD: " ) \
5251 + m_resource;
53- ms_dbg_a (t , 4 , err);
52+ ms_dbg_a (transaction , 4 , err);
5453 return true ;
5554 }
5655
57- if (t ->m_xml ->m_data .doc == NULL ) {
58- ms_dbg_a (t , 4 , " XML document tree could not " \
56+ if (transaction ->m_xml ->m_data .doc == NULL ) {
57+ ms_dbg_a (transaction , 4 , " XML document tree could not " \
5958 " be found for DTD validation." );
6059 return true ;
6160 }
6261
63- if (t ->m_xml ->m_data .well_formed != 1 ) {
64- ms_dbg_a (t , 4 , " XML: DTD validation failed because " \
62+ if (transaction ->m_xml ->m_data .well_formed != 1 ) {
63+ ms_dbg_a (transaction , 4 , " XML: DTD validation failed because " \
6564 " content is not well formed." );
6665 return true ;
6766 }
@@ -76,24 +75,24 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
7675 }
7776#endif
7877
79- cvp = xmlNewValidCtxt ();
78+ xmlValidCtxtPtr cvp = xmlNewValidCtxt ();
8079 if (cvp == NULL ) {
81- ms_dbg_a (t , 4 , " XML: Failed to create a validation context." );
80+ ms_dbg_a (transaction , 4 , " XML: Failed to create a validation context." );
8281 return true ;
8382 }
8483
8584 /* Send validator errors/warnings to msr_log */
8685 cvp->error = (xmlSchemaValidityErrorFunc)error_runtime;
8786 cvp->warning = (xmlSchemaValidityErrorFunc)warn_runtime;
88- cvp->userData = t ;
87+ cvp->userData = transaction ;
8988
90- if (!xmlValidateDtd (cvp, t ->m_xml ->m_data .doc , m_dtd )) {
91- ms_dbg_a (t , 4 , " XML: DTD validation failed." );
89+ if (!xmlValidateDtd (cvp, transaction ->m_xml ->m_data .doc , dtd. get () )) {
90+ ms_dbg_a (transaction , 4 , " XML: DTD validation failed." );
9291 xmlFreeValidCtxt (cvp);
9392 return true ;
9493 }
9594
96- ms_dbg_a (t , 4 , std::string (" XML: Successfully validated " \
95+ ms_dbg_a (transaction , 4 , std::string (" XML: Successfully validated " \
9796 " payload against DTD: " ) + m_resource);
9897
9998 xmlFreeValidCtxt (cvp);
0 commit comments