Re: _namemapper: check error from PyImport_ImportModule
"R. Tyler Ballance" <[email protected]>
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <20090607185025.GA15900@starfruit> |
On Sun, Jun 07, 2009 at 03:46:31PM -0300, Bogdano Arendartchuk wrote:
> Hello,
>
> An exception raised by __import__ could result in a segfault by
> _namemapper because it doesn't check the returned pointer from
> PyImport_ImportModule.
>
> Would it be possible to add something like the following check:
>
> --- a/src/_namemapper.c
> +++ b/src/_namemapper.c
> @@ -514,7 +514,9 @@ init_namemapper(void)
> TooManyPeriods =
> PyErr_NewException("NameMapper.TooManyPeriodsInName",NULL,NULL);
> PyDict_SetItemString(d, "NotFound", NotFound);
> PyDict_SetItemString(d, "TooManyPeriodsInName", TooManyPeriods);
> - pprintMod = PyImport_ImportModule("pprint"); /* error check this */
> + pprintMod = PyImport_ImportModule("pprint");
> + if (!pprintMod)
> + return;
> pprintMod_pformat = PyObject_GetAttrString(pprintMod, "pformat");
> Py_DECREF(pprintMod);
> /* check for errors */
Interesting, do you have a test case that causes the import of `pprint`
to raise an exception like this?
I would also say that using PyErr_Occurred() and making sure the
exception propagated further up is a better idea than just returning (or
just calling Py_FatalError())
--
-R. Tyler Ballance
Slide, Inc.
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkosC/EACgkQFCbH3D9R4W/jLACghOaM039/eMHPDm3AVwLUVOcQ 7kIAnRh2AvBFnZBEzbrIuS9w7QM8bi85 =MTh8 -----END PGP SIGNATURE-----