Skip to content

Package Constant: Check missing dsc_address instead of dsc_dtype and restore impure after using existing request#9065

Open
Noremos wants to merge 1 commit into
FirebirdSQL:masterfrom
Noremos:package_invalid_dsc_address_and_impure_usage
Open

Package Constant: Check missing dsc_address instead of dsc_dtype and restore impure after using existing request#9065
Noremos wants to merge 1 commit into
FirebirdSQL:masterfrom
Noremos:package_invalid_dsc_address_and_impure_usage

Conversation

@Noremos

@Noremos Noremos commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Original report: https://groups.google.com/g/firebird-devel/c/uPpRhaAKT0M

In the makeValue function, the value is compiled only once and then cached. Previously, the dsc_address was always present, but now it is not required for calculating the hash, so it may be missing. This leads to null pointer read/write.

The second issue is related with request impure space. First, the calls to pass1 and pass2 were missing, leading to invalid addresses being used. Second, using an existing request, its impure will be corrupt. So, it should be restored after the node is executed.

SQL to reproduce:

shell rm -rf /tmp/test.fdb;
create database ' /tmp/test.fdb';

set bail on;
set list on;
set autoterm on;
set autoddl off;
set keep_tran on;


recreate package pg_test as
begin
    procedure sp_test() returns(o smallint);
end;

recreate package body pg_test as
begin
    constant PG_BODY_CONST smallint = -10;
    procedure sp_test() returns(o smallint) as
    begin
        o = pg_body_const;
        suspend;
    end
end
;
commit;

select p.o as get_pkg_head_const_1  from pg_test.sp_test as p rows 1; -- segfault

@aafemt

aafemt commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Execution nodes are supposed to reserve space in impure area using CompilerScratch::allocImpure during compilation, remember the returned offset and during execution get the address for usage with Request::getImpure.

@Noremos Noremos changed the title Check missing dsc_address instead of dsc_dtype and restore impure after using existing request Package Constant: Check missing dsc_address instead of dsc_dtype and restore impure after using existing request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants