[bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris

From: "MauMau" <maumau307(at)gmail(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris
Date: 2013-12-24 12:55:45
Message-ID: 549B5DA0D5354DFE9787D73B07D5BFC1@maumau
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

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 least 9.2 and later?

[Problem]
The attached ECPG app crashes and dumps core with SIGBUS on Solaris for
SPARC. I used Solaris 10, and Oracle Studio to compile the app for 64-bit
build. The same app completes successfully on Linux and Windows for
x86/x564.

The steps to reproduce the problem is:
1. ecpg sigbus.pgc
2. cc -xtarget=generic64 -I<pgsql_dir>/include
sigbus.c -L<pgsql_dir>/lib -lecpg
3. a.out

When execting FETCH statement using an SQL descriptor, the app crashes at
the following line in ECPGdo(), which is in
src/interfaces/ecpg/ecpglib/execute.c:

var->value = *((char **) (var->pointer));

[Cause]
ecpg outputs the following line in the preprocessed source file:

{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0",
ECPGt_char,(cur),(long)4,(long)1,(4)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_descriptor, (desc1), 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}

So, the above line is executed in ECPGdo(). On the other hand, desc1 is not
aligned on 8-byte boundary. This unaligned access causes SIGBUS.

[Fix]
Because desc1 is a char array, else block should be executed instead of the
above path.

var->value = var->pointer;

Therefore, make ecpg pass SQL descriptor host variables to ECPGdo() with
non-zero lengths.

Regards
MauMau

Attachment Content-Type Size
ECPG_descriptor_crash.patch application/octet-stream 1009 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2013-12-24 13:31:55 Re: Planning time in explain/explain analyze
Previous Message Andres Freund 2013-12-24 12:24:15 Re: Assertion failure in base backup code path