Skip to content

Update to libxml2 version incorporating code review feedback #300

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/lxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,31 @@ static int PyXmlSec_CheckLxmlLibraryVersion(void) {
if (version == NULL) {
goto FINALIZE;
}
if (!PyTuple_Check(version) || PyTuple_Size(version) != 3) {
if (!PyTuple_Check(version) || PyTuple_Size(version) < 2) {
goto FINALIZE;
}

PyObject* major = PyTuple_GetItem(version, 0);
PyObject* minor = PyTuple_GetItem(version, 1);

if (PyErr_Occurred()) {
goto FINALIZE;
}

if (!PyLong_Check(major) || !PyLong_Check(minor)) {
goto FINALIZE;
}

if (PyLong_AsLong(major) != PyXmlSec_GetLibXmlVersionMajor() || PyLong_AsLong(minor) != PyXmlSec_GetLibXmlVersionMinor()) {
long lxml_major = PyLong_AsLong(major);
long lxml_minor = PyLong_AsLong(minor);
long xmlsec_major = PyXmlSec_GetLibXmlVersionMajor();
long xmlsec_minor = PyXmlSec_GetLibXmlVersionMinor();

if (PyErr_Occurred()) {
goto FINALIZE;
}

if (lxml_major != xmlsec_major || lxml_minor != xmlsec_minor) {
goto FINALIZE;
}

Expand All @@ -88,6 +101,10 @@ static int PyXmlSec_CheckLxmlLibraryVersion(void) {
// Cleanup our references, and return the result
Py_XDECREF(lxml);
Py_XDECREF(version);

// Clear any errors that may have occurred
PyErr_Clear();

return result;
}

Expand Down
Loading