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 crashes when trying to use wrongly declared external function [CORE1732] #2156

Closed
firebird-automations opened this issue Feb 7, 2008 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Konstantin Dombrugov (abracadabra)

my db is using GetExactTimeStampUTC function, which was declared like in fbudf.sql supplied with Firebird server:
declare external function getExactTimestampUTC
timestamp
returns parameter 1
entry_point 'getExactTimestampUTC' module_name 'fbudf';

Issue was found when I exported my db as SQL script wia Firebird Maestro. That`s how it exports getExactTimestampUtc
DECLARE EXTERNAL FUNCTION GETEXACTTIMESTAMPUTC
RETURNS TIMESTAMP
ENTRY_POINT 'getExactTimestampUTC' MODULE_NAME 'fbudf';

When I try to use udf in recreated db, server crases with a message:
The user defined function: GETEXACTTIMESTAMPUTC
referencing entrypoint: getExactTimestampUTC
in module: fbudf
caused the fatal exception: Access violation.
The code attempted to access a virtual
address without privilege to do so.
This exception will cause the Firebird server
to terminate abnormally.

It`s certainly a bug of Firebird Maestro. But the fact that server crashed cause of this is a bug of FB Server, imho

@firebird-automations
Copy link
Collaborator Author

Commented by: @AlexPeshkoff

Server has absolutely no way to know, how to call UDF, except using information in 'DECLARE EXTERNAL FUNCTION' operator. Imagine you invoke C-function, which expects some parameter to be passed, but instead receives garbage on the stack. No surprise that access violation happens when it's called. This is exactly what happened in your case. Firebird server detects access violation (you see it reported in the log file), and in theory can attempt to continue operation. But (and it was discussed many times before) it's very dangerous from database integrity POV - who knows, what dangerous things might do badly written/called UDF (remember, we can't distinguish that cases) before AV? For example, it could damage database pages buffer. Therefore the only safe action after AV in UDF is to try to log it and restart.

@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

Commented by: Konstantin Dombrugov (abracadabra)

I understand this, and it`s a pity, but question not about calling of udf, but declaration.
Exceptions and processes inside UDF are problems of udf developers, but everybody can declare funciton with wrong params that crashes DBS.

Just a suggestion:
I think It would be better to store info about parameters inside library with UDFs. In this case It`s much harder to declare different parameters. When server processing declaration statement It could check parameters declared by user.
In this case userside declaration can be simplified and look like this:
DECLARE EXTERNAL FUNCTION 'FunctionName'
ENTRY_POINT 'LibNunctionName' MODULE_NAME 'library';

@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

1 participant