To all,

        For almost a year I was not able to get sieve to work under
Solaris 8 ( 64 bit mode ) and Cyrus-imapd-2.0.X code branch. This week I
finally spent the time to go through the code and a co-worker and I
figured out the problem. I figure this might be useful information for
others. Below is a quick run-down on the system

Sun Ultra 2
Sun Forte 6.0 C Compiler
Cyrus IMAP 2.0.13 ( and whichever version of sieve comes with it )
flex 2.5.4a and lex ( Solaris 8 lex )
Compiling everything in 64 bit mode.


### The problem

        Basically in sieve/sieve-lex.c in the funtction yy_create_buffer,
the following line "b->yy_buf_size = size" was causing a segmentation
fault. The problem however is 3 lines above with the yy_flex_alloc
function. ( 2.0.13 src code ), and its a flex/lex issue not a cyrus code
issue. Also if gcc was used it would print out warnings by default, I
believe.

        Basically yy_flex_alloc uses malloc, and malloc is not declared.
The SUN compiler by default lets this go silently. However if a function
is not declarded the compiler assumes the return value is an int, which on
SUNs is 32 bits. If you are complining in 32 bit mode, pointers are 32
bits so there is no problem. However if you are compiling in 64 bit mode,
an int is still 32 bits, but a pointer is 64 bits.

http://docs.sun.com/htmlcoll/coll.33.7/iso-8859-1/CUG/conv_v9.html#8620

        So under 64 bit compile, malloc is not declared and returns a 32
bit int, to a 64 bit pointer ( b ). Malloc did not return a NULL so the
code thinks things are okay, and assigned the 32 bit int, to the 64 bit
pointer. Now when you try to use b, this causes a segmenation fault.
Flex/lex should probably define malloc or place an #include <malloc.h>,
though I am neophyte in this.


### The Temporary solution

        The quick fix was to add the line #include <malloc.h> to
sieve-lex.c, beacause this declares malloc and will therefore pass back a
pointer ( 64 bit ) and not an int.

        This will also be an issue for any other code which is compiled in
64 bit mode, and returns a pointer, yet is un-declared. My understanding
is that the flex/lex code uses mallloc. when it created the yy_flex_alloc
function, but did not add a line to declare it or include malloc.h.

### Permanent solution ???


        I am not sure what a "good" permanent fix is, but including
stdlib.h in any code which has implicitly uses functions, that returns
pointers, would be a good start. I'm trying to find a Sun C compiler that
will print warnings about implicitly used functions, to try and get a list
of functions, in the cyrus code that does this.

        Again I do want to say that this is a "quirk" with using
the Sun C Compiler, compiling in 64 bit mode, and flex/lex. Also I have to
thanx my co-worker Mark Montague for helping out and solving the final
bit.

                                        Len Smith
                                        LSA IT UNIX
                                        University of Michigan








Reply via email to