python: Fix passphrase callback wrapping.

* lang/python/helpers.c (pyPassphraseCb): Cope with 'passphrase_info'
being NULL.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-02-16 14:49:27 +01:00
parent 048c5f74b6
commit 3bdce4aa3d
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020

View File

@ -377,7 +377,21 @@ static gpgme_error_t pyPassphraseCb(void *hook,
goto leave; goto leave;
} }
PyTuple_SetItem(args, 1, PyBytes_FromString(passphrase_info)); if (passphrase_info == NULL)
{
Py_INCREF(Py_None);
PyTuple_SetItem(args, 1, Py_None);
}
else
PyTuple_SetItem(args, 1, PyUnicode_DecodeUTF8(passphrase_info,
strlen (passphrase_info),
"strict"));
if (PyErr_Occurred()) {
Py_DECREF(args);
err_status = gpg_error(GPG_ERR_GENERAL);
goto leave;
}
PyTuple_SetItem(args, 2, PyBool_FromLong((long)prev_was_bad)); PyTuple_SetItem(args, 2, PyBool_FromLong((long)prev_was_bad));
if (dataarg) { if (dataarg) {
Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */ Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */