Re: [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris - Mailing list pgsql-hackers

From Boszormenyi Zoltan
Subject Re: [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris
Date
Msg-id 52B9F300.50904@cybertec.at
Whole thread Raw
In response to [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris  ("MauMau" <maumau307@gmail.com>)
Responses Re: [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris
List pgsql-hackers
<div class="moz-cite-prefix">2013-12-24 13:55 keltezéssel, MauMau írta:<br /></div><blockquote
cite="mid:549B5DA0D5354DFE9787D73B07D5BFC1@maumau"type="cite">Hello, <br /><br /> I encountered a bug of ECPG with PG
9.2.4,which probably exists in all releases.  The attached patch is for 9.4.  Could you review and backport this to at
least9.2 and later? <br /><br /><br /> [Problem] <br /> The attached ECPG app</blockquote><br /> The app wasn't
attached,only the patch.<br /> If this is a small test app, it can also be a part of the patch in the form of a
regressiontest.<br /><br /><blockquote cite="mid:549B5DA0D5354DFE9787D73B07D5BFC1@maumau" type="cite"> crashes and
dumpscore with SIGBUS on Solaris for SPARC.  I used Solaris 10, and Oracle Studio to compile the app for 64-bit build. 
Thesame app completes successfully on Linux and Windows for x86/x564. <br /><br /> The steps to reproduce the problem
is:<br /> 1. ecpg sigbus.pgc <br /> 2. cc -xtarget=generic64 -I<pgsql_dir>/include sigbus.c
-L<pgsql_dir>/lib-lecpg <br /> 3. a.out <br /><br /> When execting FETCH statement using an SQL descriptor, the
appcrashes at the following line in ECPGdo(), which is in src/interfaces/ecpg/ecpglib/execute.c: <br /><br />   
var->value= *((char **) (var->pointer)); <br /><br /><br /> [Cause] <br /> ecpg outputs the following line in the
preprocessedsource file: <br /><br /> { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0", <br />
ECPGt_char,(cur),(long)4,(long)1,(4)*sizeof(char),<br /> ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, <br />
ECPGt_descriptor,(desc1), 0L, 0L, 0L, <br /> ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} <br /><br /> So, the
aboveline is executed in ECPGdo().  On the other hand, desc1 is not aligned on 8-byte boundary.  This unaligned access
causesSIGBUS. <br /><br /><br /> [Fix] <br /> Because desc1 is a char array, else block should be executed instead of
theabove path. <br /><br />    var->value = var->pointer; <br /><br /> Therefore, make ecpg pass SQL descriptor
hostvariables to ECPGdo() with non-zero lengths. <br /><br /><br /> Regards <br /> MauMau <br /><br /><fieldset
class="mimeAttachmentHeader"></fieldset><br/><pre wrap="">
 
</pre></blockquote><br /><br /><pre class="moz-signature" cols="90">-- 
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: <a class="moz-txt-link-freetext" href="http://www.postgresql-support.de">http://www.postgresql-support.de</a>
<aclass="moz-txt-link-freetext" href="http://www.postgresql.at/">http://www.postgresql.at/</a>
 
</pre>

pgsql-hackers by date:

Previous
From: Kohei KaiGai
Date:
Subject: Re: sepgsql: label regression test failed
Next
From: Peter Geoghegan
Date:
Subject: Re: INSERT...ON DUPLICATE KEY LOCK FOR UPDATE