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

[Bug]: Segmentation fault on execution of the request cagg_validate_query #6625

Closed
kav23alex opened this issue Feb 9, 2024 · 1 comment · Fixed by #6655
Closed

[Bug]: Segmentation fault on execution of the request cagg_validate_query #6625

kav23alex opened this issue Feb 9, 2024 · 1 comment · Fixed by #6655

Comments

@kav23alex
Copy link

What type of bug is this?

Crash

What subsystems and features are affected?

Query executor

What happened?

When executing a request:
SET search_path TO public, _timescaledb_functions;
SELECT * FROM cagg_validate_query($$ $$);
SELECT * FROM cagg_validate_query($$ $$);

TimescaleDB version affected

2.14.0

PostgreSQL version used

16

What operating system did you use?

Ubuntu 22.04

What installation method did you use?

Source

What platform did you run on?

Not applicable

Relevant log output and stack trace

(gdb)
#0  continuous_agg_validate_query (fcinfo=0x55fcc2e18d40) at /usr/include/postgresql/16/server/nodes/pg_list.h:281
#1  0x000055fcc07e09dd in ExecMakeTableFunctionResult (setexpr=0x55fcc2cdefc8, econtext=0x55fcc2cdeeb0, argContext=<optimized out>, expectedDesc=0x55fcc2cdfc40, randomAccess=false) at executor/./build/../src/backend/executor/execSRF.c:235
#2  0x000055fcc07f256a in FunctionNext (node=0x55fcc2cdeca8) at executor/./build/../src/backend/executor/nodeFunctionscan.c:95
#3  0x000055fcc07d2c5d in ExecProcNode (node=0x55fcc2cdeca8) at executor/./build/../src/include/executor/executor.h:273
#4  ExecutePlan (execute_once=<optimized out>, dest=0x55fcc2f55cd8, direction=<optimized out>, numberTuples=0, sendTuples=<optimized out>, operation=CMD_SELECT, use_parallel_mode=<optimized out>, planstate=0x55fcc2cdeca8, estate=0x55fcc2cdea90)
    at executor/./build/../src/backend/executor/execMain.c:1670
#5  standard_ExecutorRun (queryDesc=0x55fcc2eff170, direction=<optimized out>, count=0, execute_once=<optimized out>) at executor/./build/../src/backend/executor/execMain.c:365
#6  0x000055fcc09b4e15 in ExecutorRun (execute_once=<optimized out>, count=0, direction=ForwardScanDirection, queryDesc=0x55fcc2eff170) at executor/./build/../src/backend/executor/execMain.c:309
#7  PortalRunSelect (portal=0x55fcc2bf87e0, forward=<optimized out>, count=0, dest=<optimized out>) at tcop/./build/../src/backend/tcop/pquery.c:924
#8  0x000055fcc09b67d6 in PortalRun (portal=0x55fcc2bf87e0, count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized out>, dest=0x55fcc2f55cd8, altdest=0x55fcc2f55cd8, qc=0x7fffeb43a160)
    at tcop/./build/../src/backend/tcop/pquery.c:768
#9  0x000055fcc09b7a09 in exec_simple_query (query_string=0x55fcc2b3f150 "SELECT * FROM cagg_validate_query($$  $$);") at tcop/./build/../src/backend/tcop/postgres.c:1272
#10 0x000055fcc09ba727 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at tcop/./build/../src/backend/tcop/postgres.c:4654
#11 0x000055fcc0922c65 in BackendRun (port=0x55fcc2bab200, port=0x55fcc2bab200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4464
#12 BackendStartup (port=0x55fcc2bab200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4192
#13 ServerLoop () at postmaster/./build/../src/backend/postmaster/postmaster.c:1782
#14 0x000055fcc0919210 in PostmasterMain (argc=5, argv=<optimized out>) at postmaster/./build/../src/backend/postmaster/postmaster.c:1466
#15 0x000055fcc05df79d in main (argc=5, argv=0x55fcc2aac1e0) at main/./build/../src/backend/main/main.c:198
(gdb)
#0  continuous_agg_validate_query (fcinfo=0x55fcc2e18d40) at /usr/include/postgresql/16/server/nodes/pg_list.h:281
#1  0x000055fcc07e09dd in ExecMakeTableFunctionResult (setexpr=0x55fcc2cdefc8, econtext=0x55fcc2cdeeb0, argContext=<optimized out>, expectedDesc=0x55fcc2cdfc40, randomAccess=false) at executor/./build/../src/backend/executor/execSRF.c:235
#2  0x000055fcc07f256a in FunctionNext (node=0x55fcc2cdeca8) at executor/./build/../src/backend/executor/nodeFunctionscan.c:95
#3  0x000055fcc07d2c5d in ExecProcNode (node=0x55fcc2cdeca8) at executor/./build/../src/include/executor/executor.h:273
#4  ExecutePlan (execute_once=<optimized out>, dest=0x55fcc2f55cd8, direction=<optimized out>, numberTuples=0, sendTuples=<optimized out>, operation=CMD_SELECT, use_parallel_mode=<optimized out>, planstate=0x55fcc2cdeca8, estate=0x55fcc2cdea90)
    at executor/./build/../src/backend/executor/execMain.c:1670
#5  standard_ExecutorRun (queryDesc=0x55fcc2eff170, direction=<optimized out>, count=0, execute_once=<optimized out>) at executor/./build/../src/backend/executor/execMain.c:365
#6  0x000055fcc09b4e15 in ExecutorRun (execute_once=<optimized out>, count=0, direction=ForwardScanDirection, queryDesc=0x55fcc2eff170) at executor/./build/../src/backend/executor/execMain.c:309
#7  PortalRunSelect (portal=0x55fcc2bf87e0, forward=<optimized out>, count=0, dest=<optimized out>) at tcop/./build/../src/backend/tcop/pquery.c:924
#8  0x000055fcc09b67d6 in PortalRun (portal=0x55fcc2bf87e0, count=9223372036854775807, isTopLevel=<optimized out>, run_once=<optimized out>, dest=0x55fcc2f55cd8, altdest=0x55fcc2f55cd8, qc=0x7fffeb43a160)
    at tcop/./build/../src/backend/tcop/pquery.c:768
#9  0x000055fcc09b7a09 in exec_simple_query (query_string=0x55fcc2b3f150 "SELECT * FROM cagg_validate_query($$  $$);") at tcop/./build/../src/backend/tcop/postgres.c:1272
#10 0x000055fcc09ba727 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at tcop/./build/../src/backend/tcop/postgres.c:4654
#11 0x000055fcc0922c65 in BackendRun (port=0x55fcc2bab200, port=0x55fcc2bab200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4464
#12 BackendStartup (port=0x55fcc2bab200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4192
#13 ServerLoop () at postmaster/./build/../src/backend/postmaster/postmaster.c:1782
#14 0x000055fcc0919210 in PostmasterMain (argc=5, argv=<optimized out>) at postmaster/./build/../src/backend/postmaster/postmaster.c:1466
#15 0x000055fcc05df79d in main (argc=5, argv=0x55fcc2aac1e0) at main/./build/../src/backend/main/main.c:198

How can we reproduce the bug?

CREATE EXTENSION timescaledb;
SET search_path TO public, _timescaledb_functions;
SELECT * FROM cagg_validate_query($$  $$);
SELECT * FROM cagg_validate_query($$  $$);
@erimatnor
Copy link
Contributor

erimatnor commented Feb 9, 2024

@kav23alex Thanks for the bug report. I was able to reproduce and it looks like there's a lack of parameter checks in the function.

@svenklemm svenklemm added the segfault Segmentation fault label Feb 9, 2024
svenklemm added a commit that referenced this issue Feb 14, 2024
With the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
svenklemm added a commit that referenced this issue Feb 14, 2024
With the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
svenklemm added a commit that referenced this issue Feb 14, 2024
When the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
svenklemm added a commit that referenced this issue Feb 14, 2024
When the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
svenklemm added a commit that referenced this issue Feb 15, 2024
When the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
github-actions bot pushed a commit that referenced this issue Feb 15, 2024
When the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
(cherry picked from commit 7ab0566)
svenklemm added a commit that referenced this issue Feb 19, 2024
When the input to pg_parse_query does not contain anything to parse
it will return NIL. This patch adds a check for NIL to prevent the
segfault that would otherwise happen later in the code.

Fixes: #6625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants