[netsa-tools-discuss] Possible bug about IPv6 in pyfixbuf 0.8.0

Mark Thomas mthomas at cert.org
Mon Nov 11 18:20:22 EST 2019


Thank you for reporting this bug in pyfixbuf.

Your patch is valid, though I decided to address the issue a bit differently.

I expect to release a new version of pyfixbuf within the week.

Thanks again.

-Mark


-----Original Message-----
From: Łukasz Rząsik <lukasz.rzasik at gmail.com>
Date: Sat, 9 Nov 2019 20:56:55 +0100
To: <netsa-tools-discuss at cert.org>
Cc: <lukasz.rzasik at dreamlab.net>
Subject: [netsa-tools-discuss] Possible bug about IPv6 in pyfixbuf 0.8.0

Hello,

I've encountered something that looks like a bug in pyfixbuf 0.8.0.

I'm using python 3.5.6
I'm assigning a field of type DataType.IP6ADDR (I'm using Python
type ipaddress.IPv6Address) to Record object using __setitem__()
This fails with:
TypeError: Value is not an string type.

According to my analysis this is caused by:

ip6addr_to_bytes() called by _set_value() changes whatever type is passed
to python's 'bytes'.

But then in _pyfixbuf.c, in pyfixbuf_set_value(), this piece of code
compares the type with string (unicode) and fails:
    switch (type) {
      case FB_IP6_ADDR:
        if ( !IS_STRING(value) ) {
            PyErr_SetString(PyExc_TypeError,
                            "Value is not an string type.");
            return NULL;
        } else if (len != 16) {
            PyErr_Format(PyExc_ValueError,
                         "IPv6 Addresss has unexpected length %d.", len);
            return NULL;
        } else {
            string = PyBytes_AsString(value);
            memcpy(bytearray, string, len);
        }
        break;


I've prepared a patch that should fix the problem:
--- src/pyfixbuf/_pyfixbuf.c 2019-10-25 12:50:55.495431280 +0200
+++ src/pyfixbuf/_pyfixbuf.c.fixed 2019-10-25 12:52:38.175384871 +0200
@@ -73,6 +73,7 @@

 #if PY_MAJOR_VERSION >= 3
 #  define IS_BYTE(o)                (PyByteArray_Check(o))
+#  define IS_BYTES(o)               (PyBytes_Check(o))
 #  define IS_INT(o)                 (PyLong_Check(o) && !PyBool_Check(o))
 #  define IS_STRING(o)              (PyUnicode_Check(o))

@@ -89,6 +90,7 @@

 #else
 #define IS_BYTE(o)   (PyByteArray_Check(o))
+#define IS_BYTES(o)  (PyBytes_Check(o))
 #define IS_INT(o)    ((PyInt_Check(o) && !PyBool_Check(o)) ||
PyLong_Check(o))
 #define IS_STRING(o) (PyUnicode_Check(o) || PyString_Check(o))

@@ -1842,7 +1844,7 @@

     switch (type) {
       case FB_IP6_ADDR:
-        if ( !IS_STRING(value) ) {
+        if ( !IS_BYTES(value) ) {
             PyErr_SetString(PyExc_TypeError,
                             "Value is not an string type.");
             return NULL;


Please let me know if this fix is valid in your opinion or I missed
something.

Best regards,
Lukasz Rzasik


More information about the netsa-tools-discuss mailing list