Fix pointer truncation crash caused by missing get_database_name declaration#96
Conversation
…aration
PostgreSQL commit 20abdc9e82 ("Avoid including commands/dbcommands.h in
so many places") moved the declaration of get_database_name() from
commands/dbcommands.h to utils/lsyscache.h. Extensions that relied on
the old header location no longer get a proper function prototype,
causing the compiler to assume the function returns int (32-bit) instead
of char * (64-bit). On x86_64 this silently truncates the returned
pointer, leading to a segmentation fault when the truncated pointer is
later dereferenced (e.g. by strlen inside snprintf).
Use utils/lsyscache.h on PostgreSQL 19+ where the declaration lives
there, and fall back to commands/dbcommands.h on older versions where it
is still provided.
|
Base code: postgresql-19beta1 In contrib directory, When build source code, there is WARNING: Then create extension and run example query: -- create the extension -- make test configuration using parser -- add token mapping -- ts_parse Crash happens: |
|
Thanks for your patch! |
PostgreSQL commit 20abdc9e82 ("Avoid including commands/dbcommands.h in
so many places") moved the declaration of get_database_name() from
commands/dbcommands.h to utils/lsyscache.h. Extensions that relied on
the old header location no longer get a proper function prototype,
causing the compiler to assume the function returns int (32-bit) instead
of char * (64-bit). On x86_64 this silently truncates the returned
pointer, leading to a segmentation fault when the truncated pointer is
later dereferenced (e.g. by strlen inside snprintf).
Use utils/lsyscache.h on PostgreSQL 19+ where the declaration lives
there, and fall back to commands/dbcommands.h on older versions where it
is still provided.