Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 addresses :: through ::f cause spurious errors #34

Open
andrewchi opened this issue Aug 28, 2020 · 1 comment
Open

IPv6 addresses :: through ::f cause spurious errors #34

andrewchi opened this issue Aug 28, 2020 · 1 comment

Comments

@andrewchi
Copy link

Confirming what @lithammer reported in #8 (comment)_ , the following exceptions are raised for the IPv6 addresses "::", "::1", "::2", ..., "::f", which should all be valid. For some reason, the errors do not occur with "::10".

>>> import pytricia
>>> t = pytricia.PyTricia(128)
>>> t['::'] = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: error return without exception set
>>> t['::/64'] = 0
>>> t['::']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid prefix.

It is not clear to me at what point that this bug is triggered, perhaps somewhere in _key_object_to_prefix()?

@mutax
Copy link

mutax commented Apr 28, 2022

I just ran into the same issue. The SystemError might be result of returning a NULL from C to python without setting the error.

Scrolling through the Code I see at least one possible instance (picked randomly here) where this might be the case, compare how in the first return NULL is returned, in the second one the error message is set.

static PyObject *
pytricia_get(register PyTricia *obj, PyObject *args) {
    PyObject *key = NULL;
    PyObject *defvalue = NULL;

    if (!PyArg_ParseTuple(args, "O|O:get", &key, &defvalue)) {
        return NULL;
    }
    prefix_t *prefix = _key_object_to_prefix(key);
    if (!prefix) {
        PyErr_SetString(PyExc_ValueError, "Invalid prefix.");
        return NULL;
    }
    …

documenting it here in case other people stumble upon the same issue.
Not sure if I will be able to submit a pull request due to time constraints.

Currently I add a '0' in the front and end of an address as a workaround like so:

    if the_ip.startswith('::'):
        the_ip = f'0{the_ip}'
    if the_ip.endswith('::'):
        the_ip = f'{the_ip}0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants