SELECT DISTINCT "Revision", COALESCE("Message", '') AS "LogMessage"
FROM (
SELECT "Revision", "StageID" FROM "tilemaps"
UNION SELECT "Revision", "StageID" FROM "entitymaps"
UNION SELECT "Revision", "StageID" FROM "log"
) AS "revisions"
NATURAL JOIN "log"
WHERE "StageID" = :stageId
ORDER BY "Revision" DESC
can systematically crash Firebird. I've tried running the server through a debugger on my x64 Linux system and it seems to me like a null pointer dereferencing. Here follows the backtrace:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff3b60700 (LWP 12346)]
MAKE_desc (statement=0x7ffff41661e8, desc=0x8, node=0x0, null_replacement=0x0)
at ../src/dsql/make.cpp:409
409 if (node->nod_desc.dsc_dtype && !null_replacement)
(gdb) bt
Field 'stageid' does exist in both tables ('tilemaps' and 'logs'), so it CAN be used here w/o alias prefix in WHERE clause.
Confirmed crashes for similar queries (differ only in argument in right part of WHERE expression:
1) select * from (select * from mon$attachments a) a natural join mon$statements s where mon$stat_id = 0;
and
2) select * from (select * from mon$attachments a) a natural join mon$statements s where mon$stat_id = ?;
WI-V2.5.0.26074: "1)" ==> SQLSTATE = HY004/Data type unknown; "2)" ==> SQLSTATE = 08006/Error reading data from the connection.
WI-V2.5.1.26351: the same as WI-V2.5.0.26074
Modified by: @pavel-zotov
status: Closed \[ 6 \] =\> Closed \[ 6 \]
Test Details: Field 'stageid' does exist in both tables \('tilemaps' and 'logs'\), so it CAN be used here w/o alias prefix in WHERE clause\.
Confirmed crashes for similar queries \(differ only in argument in right part of WHERE expression:
1\) select \* from \(select \* from mon$attachments a\) a natural join mon$statements s where mon$stat\_id = 0;
and
2\) select \* from \(select \* from mon$attachments a\) a natural join mon$statements s where mon$stat\_id = ?;
WI\-V2\.5\.0\.26074: "1\)" ==\> SQLSTATE = HY004/Data type unknown; "2\)" ==\> SQLSTATE = 08006/Error reading data from the connection\.
WI\-V2\.5\.1\.26351: the same as WI\-V2\.5\.0\.26074
Submitted by: Daniele Cocca (jmc)
I've found that the following query:
SELECT DISTINCT "Revision", COALESCE("Message", '') AS "LogMessage" FROM ( SELECT "Revision", "StageID" FROM "tilemaps" UNION SELECT "Revision", "StageID" FROM "entitymaps" UNION SELECT "Revision", "StageID" FROM "log" ) AS "revisions" NATURAL JOIN "log" WHERE "StageID" = :stageId ORDER BY "Revision" DESC
can systematically crash Firebird. I've tried running the server through a debugger on my x64 Linux system and it seems to me like a null pointer dereferencing. Here follows the backtrace:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff3b60700 (LWP 12346)] MAKE_desc (statement=0x7ffff41661e8, desc=0x8, node=0x0, null_replacement=0x0) at ../src/dsql/make.cpp:409 409 if (node->nod_desc.dsc_dtype && !null_replacement) (gdb) bt
0 MAKE_desc (statement=0x7ffff41661e8, desc=0x8, node=0x0,
1 0x000000000067cad2 in MAKE_desc_from_list (statement=0x7ffff41661e8,
2 0x000000000067d76d in MAKE_desc (statement=0x7ffff41661e8,
3 0x000000000067cdfc in MAKE_desc (statement=0x7ffff41661e8,
4 0x000000000069cfd7 in set_parameter_type (statement=0x7ffff41661e8,
5 0x00000000006a3be7 in PASS1_node (statement=0x7ffff41661e8,
6 0x00000000006ac411 in pass1_node_psql (input=<optimized out>,
7 pass1_rse_impl (statement=0x7ffff41661e8, input=0x7ffff40f6010,
8 0x00000000006ad00e in pass1_rse (flags=0, update_lock=0x0,
9 pass1_rse_impl (statement=0x7ffff41661e8, input=0x7ffff40f5eb0, order=0x0,
10 0x00000000006afb5c in pass1_rse (flags=0, update_lock=<optimized out>,
11 PASS1_rse (statement=0x7ffff41661e8, input=<optimized out>,
12 0x00000000006b6b0d in PASS1_statement (statement=0x7ffff41661e8,
13 0x0000000000666909 in prepare (tdbb=0x7ffff3b5ec90,
14 0x000000000066ae7c in DSQL_prepare (tdbb=0x7ffff3b5ec90,
AS \"LogMessage\"\nFROM (\n\tSELECT \"Revision\", \"StageID\" FROM \"tilemaps\"\n\tUNION SELECT \"Revision\", \"StageID\" FROM \"entitymaps\"\n\tUNION SELECT \"Revision\","..., dialect=3, item_length=26,
items=0x7ffff3b5f3d8 "\~\025\004\a\t\v\f\r\016\020\021\022\023\b\005\a\t\v\f\r\016\020\021\022\023\b\265\363\377\177", buffer_length=32768, buffer=0x7ffff0a5fc08 "\~\004") at ../src/dsql/dsql.cpp:726
15 0x0000000000573d41 in jrd8_prepare (user_status=0x7ffff3b5f7f0,
16 0x000000000043b7a6 in isc_dsql_prepare_m (user_status=<optimized out>,
17 0x000000000041b702 in rem_port::prepare_statement (this=0x7ffff7fec578,
18 0x0000000000420e6e in process_packet (port=0x7ffff7fec578,
19 0x0000000000422a06 in loopThread () at ../src/remote/server.cpp:5212
20 0x0000000000436706 in run (this=<synthetic pointer>)
21 (anonymous namespace)::threadStart (arg=0x7ffff7feac70)
22 0x00007ffff66e5df0 in start_thread () from /lib/libpthread.so.0
23 0x00007ffff642b39d in clone () from /lib/libc.so.6
24 0x0000000000000000 in ?? ()
I can give the statements used to create the affected tables if needed.
Commits: FirebirdSQL/firebird@cc6d7212d88e76c7c9a6c7a106bfc53ce9661c77 FirebirdSQL/firebird@3a3a5b80f545af14cfa5b58bb2d898ecf78f4a63
====== Test Details ======
Field 'stageid' does exist in both tables ('tilemaps' and 'logs'), so it CAN be used here w/o alias prefix in WHERE clause. Confirmed crashes for similar queries (differ only in argument in right part of WHERE expression: 1) select * from (select * from mon$attachments a) a natural join mon$statements s where mon$stat_id = 0; and 2) select * from (select * from mon$attachments a) a natural join mon$statements s where mon$stat_id = ?; WI-V2.5.0.26074: "1)" ==> SQLSTATE = HY004/Data type unknown; "2)" ==> SQLSTATE = 08006/Error reading data from the connection. WI-V2.5.1.26351: the same as WI-V2.5.0.26074