From 8c45178c90702f4ca299ce942804bfed11b2345f Mon Sep 17 00:00:00 2001 Message-Id: <8c45178c90702f4ca299ce942804bfed11b2345f.1716761129.git.mdw@distorted.org.uk> From: Mark Wooding Date: Thu, 11 May 2017 10:42:15 +0100 Subject: [PATCH] utils.c: Raise exceptions from `convTHING' with null arguments. Organization: Straylight/Edgeware From: Mark Wooding This can happen as a result of using `convTHING' in an attribute `set' function, and the Python program trying to `del' the attribute. Unfortunately, these conversion functions are already being used in this context, and it leads to segfaults, e.g., from del C.Key(C.KeyFile('', C.KOPEN_WRITE | C.KOPEN_NOFILE), 0, 'k').exptime Easy fix. --- util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util.c b/util.c index ed56e99..8fab0bf 100644 --- a/util.c +++ b/util.c @@ -60,6 +60,7 @@ int convulong(PyObject *o, void *pp) unsigned long *p = pp; PyObject *t; + if (!o) VALERR("can't delete"); if (PyInt_Check(o)) { i = PyInt_AS_LONG(o); if (i < 0) VALERR("must be nonnegative"); @@ -131,8 +132,11 @@ end: int convbool(PyObject *o, void *pp) { + if (!o) VALERR("can't delete"); *(int *)pp = PyObject_IsTrue(o); return (1); +end: + return (0); } /*----- Type messing ------------------------------------------------------*/ -- [mdw]