(forw) [goedson@debian.org: Re: [Pkg-qof-maintainers] Bug#337374:]

Neil Williams linux at codehelp.co.uk
Mon Nov 7 14:41:04 UTC 2005


On Monday 07 November 2005 1:28 pm, Goedson wrote:
> Looking at the code of the function qof_gobject_getter, I seem to have
> found a bug. See the piece of code below:
>
> if (G_IS_PARAM_SPEC_BOOLEAN(gps))
>   {
>     long ival;
>
>     GValue gval = {G_TYPE_INVALID};
>     g_value_init (&gval, G_TYPE_BOOLEAN);
>     g_object_get_property (gob, getter->param_name, &gval);
>
>     ival = g_value_get_boolean (&gval);
>     return (gpointer) ival;
>   }
>
> Here, we store a gboolean value in a long and the cast it to a
> gpointer before returning. If this value will be used as a gpointer by
> the caller (eg. trying to dereference it) we'll probably get a
> Segmentation Fault as a result. Is this reasoning right or am I
> completely wrong about how all of this works?

I think you're right - the original patch may reveal a problem.

Elsewhere I use GPOINTER_TO_INT to cast from gpointer to gboolean:
(qofsession.c:321)
partial = (gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
qof_book_set_data(book, PARTIAL_QOFBOOK, (gboolean*)TRUE);
(that will change to GINT_TO_POINTER(TRUE) in 0.6.1)

I think we should change the block to:

if (G_IS_PARAM_SPEC_BOOLEAN(gps))
  {
    gboolean ival;
    
    GValue gval = {G_TYPE_INVALID};
    g_value_init (&gval, G_TYPE_BOOLEAN);
    g_object_get_property (gob, getter->param_name, &gval);

    ival = g_value_get_boolean (&gval);
    return GINT_TO_POINTER( ival);
  }

GINT_TO_POINTER should then do the right thing on 64bit.
(qofgobj.c:145)

Andreas - does that compile on 64bit?

The value would be accessed using (from qof_book_merge.c:190):
boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
booleanImport = boolean_getter(mergeEnt, qtparam);

That may also have to be changed to
booleanImport = (gboolean) GPOINTER_TO_INT(qtparam->param_getfcn);

"These macros ONLY allow storing integers in pointers, and only preserve 32 
bits of the integer; values outside the range of a 32-bit integer will be 
mangled."

Note that QOF_TYPE_INT64 isn't actually supported by qofgobj.c.
PWARN ("unhandled parameter type %s for paramter %s", 
          G_PARAM_SPEC_TYPE_NAME(gps), getter->param_name);

-- 

Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/pkg-qof-maintainers/attachments/20051107/28759bb5/attachment.pgp


More information about the Pkg-qof-maintainers mailing list