Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server crash when libfbclient used in UDF [CORE2219] #2647

Closed
firebird-automations opened this issue Nov 30, 2008 · 10 comments
Closed

Server crash when libfbclient used in UDF [CORE2219] #2647

firebird-automations opened this issue Nov 30, 2008 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: b0bik (b0bik)

Attachments:
libtest.so

Call to isc_decode_timestamp in UDF declared as:

procedure isc_decode_timestamp(ib_date : PISC_TIMESTAMP; tm_date : PTM); cdecl; external 'fbclient';

causes fbserver to terminate.

Firebrid.log:

/opt/fb21ss/bin/fbguard: /opt/fb21ss/bin/fbserver terminated abnormally (-1)

The same happens on 2.1.1, 2.1.2, 2.1.2-debug
(I have a 2.1.2 version from http://www.dqteam.com/fb2/)

@firebird-automations
Copy link
Collaborator Author

Modified by: b0bik (b0bik)

priority: Minor [ 4 ] => Critical [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: b0bik (b0bik)

Version: 2.1.1 [ 10223 ]

description: Call to isc_decode_timestamp in UDF declared as:

procedure isc_decode_timestamp(ib_date : PISC_TIMESTAMP; tm_date : PTM); cdecl; external 'fbclient';

cause fbserver to terminate.

Firebrid.log:

/opt/fb21ss/bin/fbguard: /opt/fb21ss/bin/fbserver terminated abnormally (-1)

The same happen on 2.1.1, 2.1.2, 2.1.2-debug
(I have a 2.1.2 version from http://www.dqteam.com/fb2/)

=>

Call to isc_decode_timestamp in UDF declared as:

procedure isc_decode_timestamp(ib_date : PISC_TIMESTAMP; tm_date : PTM); cdecl; external 'fbclient';

causes fbserver to terminate.

Firebrid.log:

/opt/fb21ss/bin/fbguard: /opt/fb21ss/bin/fbserver terminated abnormally (-1)

The same happens on 2.1.1, 2.1.2, 2.1.2-debug
(I have a 2.1.2 version from http://www.dqteam.com/fb2/)

Version: 2.1.2 [ 10270 ] =>

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

As you have a debug version, it's worth setting up your system to generate the core dumps and posting here the stack trace.

@firebird-automations
Copy link
Collaborator Author

Commented by: b0bik (b0bik)

Hello

Once again. After removing all fb* stuff from both machines (Windows and Linux) I downloaded two archives:

Firebird-2.1.1.17910-0_Win32.zip - for Windows and
FirebirdSS-2.1.1.17910-0.ntpl.i686.tar.gz.tar for Linux

After "instalation" I did following things:

1. aliases.conf - new line pointing to my fdb file
2. firebird.conf:
RemoteServicePort = 5005
UdfAccess = Restrict UDF
BugcheckAbort = 1
3. Restart firebird server

I created two version of library test. For Windows - Turbo Delphi, for Linux - Free Pascal Compiler:

test.dpr:

library test;

uses funcs in 'funcs.pas';

exports ftest;

begin
end.

funcs.pas:

unit funcs;

interface

uses Types;

type

TM = record
tm_sec: integer;
tm_min: integer;
tm_hour: integer;
tm_mday: integer;
tm_mon: integer;
tm_year: integer;
tm_wday: integer;
tm_yday: integer;
tm_isdst: integer;
end;

ISC_TIMESTAMP = record
timestamp_data: LongInt;
timestamp_time: DWord;
end;

PTM = ^TM;
PISC_TIMESTAMP = ^ISC_TIMESTAMP;

procedure isc_decode_timestamp(ib_date: PISC_TIMESTAMP; tm_date: PTM); cdecl; external 'fbclient';
function ib_util_malloc(l: integer): pointer; cdecl; external 'ib_util';

function ftest(aDateTime : PISC_TIMESTAMP): Integer; cdecl;

implementation

function ftest(aDateTime: PISC_TIMESTAMP): Integer; cdecl;
var theTM: TM;
begin
Result := 0;
isc_decode_timestamp(aDateTime, @thetm); {*}
Result := 1;
end;

end.

The only one difference between Windows and Linux is calling convention to fbclient (Windows stdcall, Linux cdecl). After building library I copied it into UDF directory (/opt/firebird/UDF/, c:\program files\firebird_211\UDF)

I declared external function using:

DECLARE EXTERNAL FUNCTION FTEST
TIMESTAMP NULL
RETURNS INTEGER BY VALUE
ENTRY_POINT 'ftest'
MODULE_NAME 'test'

After committing, I connected to my database using isql utility and run a query:

select ftest(current_timestamp) from rdb$database

Windows:

FTEST

  1

Linux - nothing, query execution never ends. But neither fbserver nor fbguard process takes lot of CPU time. When I connect to Linux machine from Windows (using flamerobin) and execute the same query, flame writes:

"Starting transaction ..."

and nothing happens too.

When I comment line marked with {*} in my udf everything works OK.

Attached files:

http://libtest.so - compiled version of my simple udf.

@firebird-automations
Copy link
Collaborator Author

Commented by: b0bik (b0bik)

udf

@firebird-automations
Copy link
Collaborator Author

Modified by: b0bik (b0bik)

Attachment: http://libtest.so [ 11232 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

assignee: Alexander Peshkov [ alexpeshkoff ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Your pascal declaration of struct tm does not match one used in C++ in linux:
struct tm
{
int tm_sec; /* Seconds. [0-60] (1 leap second) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/

#⁠ifdef __USE_BSD
long int tm_gmtoff; /* Seconds east of UTC. */
__const char *tm_zone; /* Timezone abbreviation. */
#⁠else
long int __tm_gmtoff; /* Seconds east of UTC. */
__const char *__tm_zone; /* Timezone abbreviation. */
#⁠endif
};

Therefore return address on the stack is overwritten.

@firebird-automations
Copy link
Collaborator Author

Modified by: @AlexPeshkoff

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants