Skip to content

Segment crash (SIGSEGV) when creating in-place tablespace with empty LOCATION #1627

@yjhjstz

Description

@yjhjstz

Bug Description

When creating an in-place tablespace with allow_in_place_tablespaces=on and empty LOCATION '', segment processes crash with SIGSEGV.

How to Reproduce

SET allow_in_place_tablespaces=on;
CREATE TABLESPACE dropme_ts1 LOCATION '';

The QD dispatches the CREATE TABLESPACE statement to QE segments. On the segments, stmt->location is NULL (not empty string), causing pstrdup(NULL) to crash.

Stack Trace from Segment Core Dump

#0  raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  StandardHandlerForSigillSigsegvSigbus_OnMainThread (processName="Segment process", postgres_signal_arg=11) at elog.c:5353
#2  CdbProgramErrorHandler (postgres_signal_arg=11) at postgres.c:3897
...
#5  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#6  MemoryContextStrdup (context=0x55f89dad74d0, string=0x0) at mcxt.c:1527
#7  pstrdup (in=0x0) at mcxt.c:1539
#8  CreateTableSpace (stmt=0x55f89dab2cc0) at tablespace.c:331

(gdb) p stmt->location
$1 = 0x0

Root Cause

In CreateTableSpace() (src/backend/commands/tablespace.c), line 331:

if (!location)
    location = pstrdup(stmt->location);

When CREATE TABLESPACE ... LOCATION '' is dispatched from QD to QE, the serialization/deserialization of CreateTableSpaceStmt converts the empty string "" to NULL. On the QE, pstrdup(NULL) causes a segfault.

Fix

Add a NULL guard:

if (!location)
    location = pstrdup(stmt->location ? stmt->location : "");

This preserves the in-place tablespace semantics (empty string = in-place) while preventing the NULL pointer dereference on segments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions