[Python-Dev] buglet in long("123\0", 10)

Guido van Rossum guido at python.org
Mon Jan 15 06:16:52 CET 2007


On 1/14/07, Calvin Spealman <ironfroggy at gmail.com> wrote:
> Is it a more general problem that null-terminated strings are used
> with data from strings we specifically allow to contain null bytes?
> Perhaps a migration of *FromString() to *FromStringAndSize()
> functions, or taking Python string object pointers, would be a more
> general solution to set as a goal, so this sort of thing can't crop up
> down the road, again.

Most of the time this is taken care of by the argument type codes
passed to PyArg_ParseTuple() and friends. If you use 's' then it
assumes the string is for consumption of C code that uses
null-termination, and it checks that there are no null bytes. Try
open("foo\0").

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list