|
| 1 | +// test cases for rule CWE-611 |
| 2 | + |
| 3 | +#include "tests.h" |
| 4 | + |
| 5 | +// --- |
| 6 | + |
| 7 | +typedef unsigned int XMLCh; |
| 8 | + |
| 9 | +class XMLUni |
| 10 | +{ |
| 11 | +public: |
| 12 | + static const XMLCh fgXercesDisableDefaultEntityResolution[]; |
| 13 | +}; |
| 14 | + |
| 15 | +class SAX2XMLReader |
| 16 | +{ |
| 17 | +public: |
| 18 | + void setFeature(const XMLCh *feature, bool value); |
| 19 | + void parse(const InputSource &data); |
| 20 | +}; |
| 21 | + |
| 22 | +class XMLReaderFactory |
| 23 | +{ |
| 24 | +public: |
| 25 | + static SAX2XMLReader *createXMLReader(); |
| 26 | +}; |
| 27 | + |
| 28 | +// --- |
| 29 | + |
| 30 | +void test3_1(InputSource &data) { |
| 31 | + SAX2XMLReader *p = XMLReaderFactory::createXMLReader(); |
| 32 | + |
| 33 | + p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED] |
| 34 | +} |
| 35 | + |
| 36 | +void test3_2(InputSource &data) { |
| 37 | + SAX2XMLReader *p = XMLReaderFactory::createXMLReader(); |
| 38 | + |
| 39 | + p->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true); |
| 40 | + p->parse(data); // GOOD |
| 41 | +} |
| 42 | + |
| 43 | +SAX2XMLReader *p_3_3 = XMLReaderFactory::createXMLReader(); |
| 44 | + |
| 45 | +void test3_3(InputSource &data) { |
| 46 | + p_3_3->parse(data); // BAD (parser not correctly configured) [NOT DETECTED] |
| 47 | +} |
| 48 | + |
| 49 | +SAX2XMLReader *p_3_4 = XMLReaderFactory::createXMLReader(); |
| 50 | + |
| 51 | +void test3_4(InputSource &data) { |
| 52 | + p_3_4->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true); |
| 53 | + p_3_4->parse(data); // GOOD |
| 54 | +} |
| 55 | + |
| 56 | +SAX2XMLReader *p_3_5 = XMLReaderFactory::createXMLReader(); |
| 57 | + |
| 58 | +void test3_5_init() { |
| 59 | + p_3_5->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true); |
| 60 | +} |
| 61 | + |
| 62 | +void test3_5(InputSource &data) { |
| 63 | + test3_5_init(); |
| 64 | + p_3_5->parse(data); // GOOD |
| 65 | +} |
0 commit comments