2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_3554
# title: Server crashes during prepare or throws incorrect parsing error if the remotely passed SQL query is empty
# decription:
# Checked on:
# 4.0.0.1635 SS: 1.364s.
# 4.0.0.1633 CS: 1.674s.
# 3.0.5.33180 SS: 0.822s.
# 3.0.5.33178 CS: 1.233s.
#
# tracker_id: CORE-3554
# min_versions: ['3.0']
# versions: 3.0
# qmid: None
import pytest
from firebird . qa import db_factory , isql_act , Action
# version: 3.0
# resources: None
substitutions_1 = [ ( ' Data source : Firebird::localhost:.* ' , ' Data source : Firebird::localhost: ' ) , ( ' .*Unexpected end of command.* ' , ' .*Unexpected end of command ' ) , ( ' -At block line: [ \\ d]+, col: [ \\ d]+ ' , ' -At block line ' ) ]
init_script_1 = """ """
db_1 = db_factory ( sql_dialect = 3 , init = init_script_1 )
test_script_1 = """
- - See issues in ticket :
- - " application either passes the empty SQL text to prepare, or passes a " too long " SQL text (64KB or 128KB etc)
- - so its length becomes zero as a result of conversion into USHORT ( unsigned 16 - bit integer ) which represents
- - the supported SQL text length . "
- - Test was made only for 3.0 because 2.5 allows to pass in ES much longer string than 32 K .
- - 30.07 .2015 : at least since build #31948 first ES (which passes literal of length = 32766 bytes) no more fails.
- - Previous expected std_err :
- - Statement failed , SQLSTATE = 42000
- - Dynamic SQL Error
- - - SQL error code = - 104
- - - String literal with 32766 bytes exceeds the maximum length of 32765 bytes
- - has been removed .
- - Also , std_err has been changed for 2 nd ES ( which passes empty literal ) . Was :
- - Statement failed , SQLSTATE = 42000
- - Execute statement error at isc_dsql_prepare :
- - 335544608 : Unexpected end of command
- - Statement :
- - Data source : Firebird : : localhost : C : \\FBTESTING \\QA \\FBT - REPO \\TMP \\E30 . FDB
set list on ;
set term ^ ;
execute block returns ( n int ) as
declare b blob ;
begin
- - Try to pass statement with total char length ( including delimiters , ` select ` and ` from rdb $ database ` ) = 32766 bytes .
- - This should raise exception in 3.0 :
execute statement ' select ' ' 1qwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwer
on external ( ' localhost: ' | | rdb $ get_context ( ' SYSTEM ' , ' DB_NAME ' ) ) as user ' sysdba ' password ' masterkey ' role ' R2 '
into b ;
n = octet_length ( b ) ;
suspend ;
end
^
execute block returns ( n int ) as
begin
- - Try to pass empty statement . This should raise exception , but server must not crach :
execute statement ' '
on external ( ' localhost: ' | | rdb $ get_context ( ' SYSTEM ' , ' DB_NAME ' ) ) as user ' sysdba ' password ' masterkey ' role ' R2 '
;
end
^
set term ; ^
commit ;
- - | | | | | | | | | | | | | | | | | | | | | | | | | | | |
- - ###################################||| FB 4.0+, SS and SC |||##############################
- - | | | | | | | | | | | | | | | | | | | | | | | | | | | |
- - If we check SS or SC and ExtConnPoolLifeTime > 0 ( config parameter FB 4.0 + ) then current
- - DB ( bugs . core_NNNN . fdb ) will be ' captured ' by firebird . exe process and fbt_run utility
- - will not able to drop this database at the final point of test .
- - Moreover , DB file will be hold until all activity in firebird . exe completed and AFTER this
- - we have to wait for < ExtConnPoolLifeTime > seconds after it ( discussion and small test see
- - in the letter to hvlad and dimitr 13.10 .2019 11 : 10 ) .
- - This means that one need to kill all connections to prevent from exception on cleanup phase :
- - SQLCODE : - 901 / lock time - out on wait transaction / object < this_test_DB > is in use
- - #############################################################################################
delete from mon $ attachments where mon $ attachment_id != current_connection ;
commit ;
"""
act_1 = isql_act ( ' db_1 ' , test_script_1 , substitutions = substitutions_1 )
expected_stdout_1 = """
N 32739
"""
expected_stderr_1 = """
Statement failed , SQLSTATE = 42000
Execute statement error at isc_dsql_prepare :
335544569 : Dynamic SQL Error
335544436 : SQL error code = - 104
335544851 : Unexpected end of command - line 1 , column 1
Statement :
Data source : Firebird : : localhost : C : \\MIX irebird \\QA bt - repo mp \\E30 . FDB
- At block line : 4 , col : 7
"""
@pytest.mark.version ( ' >=3.0 ' )
2021-04-28 12:42:11 +02:00
def test_1 ( act_1 : Action ) :
2021-04-26 20:07:00 +02:00
act_1 . expected_stdout = expected_stdout_1
act_1 . expected_stderr = expected_stderr_1
act_1 . execute ( )
assert act_1 . clean_expected_stderr == act_1 . clean_stderr
assert act_1 . clean_expected_stdout == act_1 . clean_stdout