python: Don't access gpgme with wrapped=None.

* lang/python/src/core.py (GpgmeWrapper, Context): Check self.wrapped
is valid.

--

GnuPG-bug-id: 6060
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-08-05 14:57:32 +09:00
parent b2f224a471
commit 180899c7c3

View File

@ -106,9 +106,13 @@ class GpgmeWrapper(object):
set_func = getattr(gpgme, "{}set_{}".format(self._cprefix, key)) set_func = getattr(gpgme, "{}set_{}".format(self._cprefix, key))
def get(slf): def get(slf):
if not slf.wrapped:
return False
return bool(get_func(slf.wrapped)) return bool(get_func(slf.wrapped))
def set_(slf, value): def set_(slf, value):
if not slf.wrapped:
return
set_func(slf.wrapped, bool(value)) set_func(slf.wrapped, bool(value))
p = property(get, set_, doc="{} flag".format(key)) p = property(get, set_, doc="{} flag".format(key))
@ -135,6 +139,8 @@ class GpgmeWrapper(object):
if self._errorcheck(name): if self._errorcheck(name):
def _funcwrap(slf, *args): def _funcwrap(slf, *args):
if not slf.wrapped:
return None
result = func(slf.wrapped, *args) result = func(slf.wrapped, *args)
if slf._callback_excinfo: if slf._callback_excinfo:
gpgme.gpg_raise_callback_exception(slf) gpgme.gpg_raise_callback_exception(slf)
@ -142,6 +148,8 @@ class GpgmeWrapper(object):
else: else:
def _funcwrap(slf, *args): def _funcwrap(slf, *args):
if not slf.wrapped:
return None
result = func(slf.wrapped, *args) result = func(slf.wrapped, *args)
if slf._callback_excinfo: if slf._callback_excinfo:
gpgme.gpg_raise_callback_exception(slf) gpgme.gpg_raise_callback_exception(slf)
@ -1098,6 +1106,8 @@ class Context(GpgmeWrapper):
@property @property
def signers(self): def signers(self):
"""Keys used for signing""" """Keys used for signing"""
if not self.wrapped:
return None
return [self.signers_enum(i) for i in range(self.signers_count())] return [self.signers_enum(i) for i in range(self.signers_count())]
@signers.setter @signers.setter
@ -1133,6 +1143,8 @@ class Context(GpgmeWrapper):
@property @property
def home_dir(self): def home_dir(self):
"""Engine's home directory""" """Engine's home directory"""
if not self.wrapped:
return None
return self.engine_info.home_dir return self.engine_info.home_dir
@home_dir.setter @home_dir.setter