[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#279323: Fix for Zope segfault on amd64



hi everybody 

Does zope2.7 segfauls as well?

In zope2.7 the line is

  if (!PyArg_ParseTuple(args, "sI:initgroups", &username, &igid))

From  http://www.python.org/doc/2.4/api/arg-parsing.html

    "I" (integer) [unsigned int]
     Convert a Python integer to a C unsigned int, without overflow checking. New in version 2.3.


I also found this bit from the 'info libc6' 
    With the `-Wformat' option, the GNU C compiler checks calls to
 `scanf' and related functions.  It examines the format string and
 verifies that the correct number and types of arguments are supplied.
 There is also a GNU C syntax to tell the compiler that a function you
 write uses a `scanf'-style format string.  *Note Declaring Attributes
 of Functions: (gcc.info)Function Attributes, for more information.

Does this apply to PyArg_ParseTuple ?


a.

On Sat, Jan 22, 2005 at 02:00:17AM -0500, Per Bojsen wrote:
> Hi,
> 
> I did some debugging and found out that the segfault in Zope on amd64
> is due to some non-64-bit-compatible code in the initgroups.c source
> file (lib/Components/initgroups/initgroups.c in the Zope source
> package).  Here is a patch that fixes this problem:
> 
> --- initgroups.c~	2002-07-25 17:54:02.000000000 -0400
> +++ initgroups.c	2005-01-22 01:36:44.422203184 -0500
> @@ -25,7 +25,16 @@
>  	char *username;
>  	gid_t gid;
>  
> +#if defined(__x86_64__) || defined(__amd64) || defined(__amd64__)
> +	/* gid_t is a 32-bit integer on amd64 so we should use the i
> +	   format specifier as the l specifier indicates a long which
> +	   is 64 bits.  This fixes a segfault caused by
> +	   PyArg_ParseTuple() overwriting the lower 32 bits of
> +	   username when setting gid.  */
> +	if (!PyArg_ParseTuple(args, "si:initgroups", &username, &gid))
> +#else
>  	if (!PyArg_ParseTuple(args, "sl:initgroups", &username, &gid))
> +#endif
>  		return NULL;
>  
>  	if (initgroups(username, gid) == -1)
> 
> With this patch I no longer get segfaults and I am able to bring up
> the Zope management interface.
> 
> Hope this helps,
> Per
> 
> -- 
> Per Bojsen                                              <per.bojsen@comcast.net>
> 7 Francis Road
> Billerica, MA 01821-3618
> USA
> 

-- 
Andrea Mennucc
 "Ukn ow,Ifina llyfixe dmysp acebar.ohwh atthef"

Attachment: pgpeDsOsIkH6w.pgp
Description: PGP signature


Reply to: