Skip to content

Commit

Permalink
Merge pull request #300 from jonathangreen/feature/version-check-code…
Browse files Browse the repository at this point in the history
…-review-updates

Update to libxml2 version incorporating code review feedback
  • Loading branch information
jimjag committed Apr 1, 2024
2 parents 1525fe0 + b184cfe commit 749c7fa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lxml.c
Expand Up @@ -67,12 +67,18 @@ 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);
if (major == NULL) {
goto FINALIZE;
}
PyObject* minor = PyTuple_GetItem(version, 1);
if (minor == NULL) {
goto FINALIZE;
}

if (!PyLong_Check(major) || !PyLong_Check(minor)) {
goto FINALIZE;
Expand All @@ -85,9 +91,13 @@ static int PyXmlSec_CheckLxmlLibraryVersion(void) {
result = 0;

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

// Cleanup our references, and return the result
Py_XDECREF(lxml);
Py_XDECREF(version);

return result;
}

Expand Down

0 comments on commit 749c7fa

Please sign in to comment.