> On Tue, Nov 07, 2006, Bernhard Rosenkraenzer wrote:

> > gcc 4.2 no longer allows function casting - which is used
> > rather heavily by
> > openssl. (To make things worse, it compiles but inserts abort()
> > statements
> > resulting in app crashes).

> Ugh, I would've thought that flagging a compiliation error would make more
> sense rather that outputting bad code...

It is perfectly reasonable (though certainly not optimal) for a compiler to
output bad code when the code it's compiling invokes undefined behavior.

> > You can see http://gcc.gnu.org/ml/gcc/2006-07/msg00037.html
> >
> > for a discussion on the gcc devel list.
> >
> > Is there a fix to make OpenSSL compatible with gcc 4.2/4.3 yet?

> No there isn't yet, some technique will be needed to make this
> still work by
> tweaking some of the macros. Does casting a function to (void *)
> first then
> the function cast work?

Not if by work you mean anything more than accidentally happen to work on
some platforms. There is no reason a 'void (*) (struct bar *);' needs to be
even remotely like a 'void (*) (char *);'. OpenSSL should be fixed to cast
the parameters, not the functions.

Look at this code:

char *  PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
                pem_password_cb *cb, void *u);

#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
        (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)

#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
        (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char
**)x,cb,u)

This is just wrong. A pointer to d2i_X509 and a pointer to d2i_SSL_SESSION
are of different types. You cannot cast them into a common type and then
write a function that can call either of them through such a pointer.

The error is *NOT* from casting function pointers (like you must do to the
return from 'dlsym'). It's from casting a pointer to a function of one type
into a function of *another* type and then *calling* it through that
pointer.

DS


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to