1
1
/*
2
2
* 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/)
4
4
*
5
5
* You may not use this file except in compliance with
6
6
* 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) {
43
43
}
44
44
45
45
46
- bool ValidateDTD::evaluate (Transaction *t, const std::string &str) {
47
- xmlValidCtxtPtr cvp;
46
+ bool ValidateDTD::evaluate (Transaction *transaction, const std::string &str) {
48
47
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 ) {
51
50
std::string err = std::string (" XML: Failed to load DTD: " ) \
52
51
+ m_resource;
53
- ms_dbg_a (t , 4 , err);
52
+ ms_dbg_a (transaction , 4 , err);
54
53
return true ;
55
54
}
56
55
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 " \
59
58
" be found for DTD validation." );
60
59
return true ;
61
60
}
62
61
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 " \
65
64
" content is not well formed." );
66
65
return true ;
67
66
}
@@ -76,24 +75,24 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
76
75
}
77
76
#endif
78
77
79
- cvp = xmlNewValidCtxt ();
78
+ xmlValidCtxtPtr cvp = xmlNewValidCtxt ();
80
79
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." );
82
81
return true ;
83
82
}
84
83
85
84
/* Send validator errors/warnings to msr_log */
86
85
cvp->error = (xmlSchemaValidityErrorFunc)error_runtime;
87
86
cvp->warning = (xmlSchemaValidityErrorFunc)warn_runtime;
88
- cvp->userData = t ;
87
+ cvp->userData = transaction ;
89
88
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." );
92
91
xmlFreeValidCtxt (cvp);
93
92
return true ;
94
93
}
95
94
96
- ms_dbg_a (t , 4 , std::string (" XML: Successfully validated " \
95
+ ms_dbg_a (transaction , 4 , std::string (" XML: Successfully validated " \
97
96
" payload against DTD: " ) + m_resource);
98
97
99
98
xmlFreeValidCtxt (cvp);
0 commit comments