Browse Source

[1258] ported the C++ fromWireShortBuffer test to python. this required
more careful exception handling in the wrapper, and as a result it resolves

JINMEI Tatuya 13 years ago
parent
commit
c1a72c46b5

+ 12 - 0
src/lib/dns/python/message_python.cc

@@ -673,6 +673,18 @@ Message_fromWire(PyObject* const pyself, PyObject* args) {
         } catch (const MessageTooShort& mts) {
             PyErr_SetString(po_MessageTooShort, mts.what());
             return (NULL);
+        } catch (const InvalidBufferPosition& ex) {
+            PyErr_SetString(po_DNSMessageFORMERR, ex.what());
+            return (NULL);
+        } catch (const exception& ex) {
+            const string ex_what =
+                "Error in Message.from_wire: " + string(ex.what());
+            PyErr_SetString(PyExc_RuntimeError, ex_what.c_str());
+            return (NULL);
+        } catch (...) {
+            PyErr_SetString(PyExc_RuntimeError,
+                            "Unexpected exception in Message.from_wire");
+            return (NULL);
         }
     }
 

+ 4 - 0
src/lib/dns/python/tests/message_python_test.py

@@ -469,6 +469,10 @@ test.example.com. 3600 IN A 192.0.2.2
         self.assertEqual("192.0.2.2", rdata[1].to_text())
         self.assertEqual(2, len(rdata))
 
+    def test_from_wire_short_buffer(self):
+        data = read_wire_data("message_fromWire22.wire")
+        self.assertRaises(DNSMessageFORMERR, self.p.from_wire, data[:-1])
+
     def test_from_wire_combind_rrs(self):
         factoryFromFile(self.p, "message_fromWire19.wire")
         rrset = self.p.get_section(Message.SECTION_ANSWER)[0]