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

isc_encode_timestamp and isc_decode timestamp crach firebird superserver if used in UDF [CORE4088] #4416

Open
firebird-automations opened this issue Apr 23, 2013 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: christophe derenne (cdr60530)

Votes: 1

Using a personnal udf library that works since a long time ago, from firebird 1 to firebird 2.5 (classic server 32 bits only)
Trying to migrate to firebird superserver 64 bits.
Own source compiled without troubles in 64 bits mode, using gcc
linking OK (using ld) excepts necessity to make a symbolink link to http://fbudf.so in /var/lib64 otherwire, http://fbudf.so is not found found when executing (small bug in firebird installation ?)

But all functions that uses isc_encode_timestamp or isc_decode_timestamp makes firebird superserver crash.

Exemple :

ISC_TIMESTAMP * First_Day_Of(int *,int *);
ISC_TIMESTAMP * First_Day_Of(mm,aa)

 int \*mm,\*aa;

{
ISC_TIMESTAMP *buffer = (ISC_TIMESTAMP*)ib_util_malloc(sizeof(ISC_TIMESTAMP));
time_t t;
typedef struct tm tm;
struct tm{
int tm_sec;int tm_min;int tm_hour;
int tm_mday;int tm_mon;int tm_year;
int tm_wday;int tm_yday;int tm_isdst;
};
tm *currtime = (tm*)ib_util_malloc(sizeof( tm));
t = time(NULL);
currtime = localtime(&t);
currtime->tm_year = ( *aa + currtime->tm_year );
currtime->tm_mon = ( *mm - 1 );
currtime->tm_mday = 1;
currtime->tm_sec = 0;
currtime->tm_min = 0;
currtime->tm_hour = 0;
isc_encode_timestamp(currtime,buffer);
return buffer;
}

This code code works on Firebird classique 32 bits, (Linux and windows) not on firebird superserver 64 bits.
Don't know about firebird-superserver 32 bits.

@firebird-automations
Copy link
Collaborator Author

Modified by: christophe derenne (cdr60530)

priority: Major [ 3 ] => Critical [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

security: Developers [ 10012 ] =>

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

Out of curiosity, why you declare struct tm yourself instead of using the standard one from time.h?
Why do you need a memory leak? I see currtime allocated dynamically and the new pointer is lost two lines below.
How is this UDF declared in the database?

@firebird-automations
Copy link
Collaborator Author

Commented by: christophe derenne (cdr60530)

Hi, sorry, i reply to you via email and it seems that you've not received my answer, so, i repeat it :

First thanks for your message : you're the first one who answsers me.

Before registering on firebird bu tracker, I've tried everything during 10 days.
replacing ib_malloc by malloc, using time.h instead of declaring my own tm structure etc....
If I ask the trackers, this is because I don't know what to do and I don't found any answser in google.

But You have to know that I've tried a very small udf that just do an is_encode_timestamp with the same issue.
This is strange because It works with firebird classic 32 bits for a long time, using on result sets with hundred of thousands rows and it works with a single test programme using this shared object

So, to answer your question this is how I've declared this functions in Firebird :

DECLARE EXTERNAL FUNCTION FIRST_DAY_OF
Integer, Integer
RETURNS Timestamp
ENTRY_POINT 'First_Day_Of'
MODULE_NAME 'udflib';

(of course my shared object's name is http://udflib.so)

Usage is : select First_Day_Of(1,-1) from rdb$database give you the first day of january of the last year (2012-01-01')
replace second parameter (-1) by 0 to change to the current year, by 1 to change to the next year and so on.
replace first parameter by 2..12 to change the month

Christophe

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

1 participant