pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Ignore not-yet-defined Portals in pg_cursors view. 7+ messages / 1 participants [nested] [flat]
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3daeb539a66acce5d8870b2b0d99d4ec9a2c0314 Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5c17f5a6392f0367236c912e36708bf332ff8aab Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/f8d9a9f21e2fec4f67af7b430b981b6e6e7a0906 Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5de77b609cbeffcb0b9a570f3848c60bc99ca7fa Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4a17acd0dbb6d173e776ba5f7d16804a77bff5bf Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/aef75219cc221cd4990eaec7d4213d85ed945069 Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Ignore not-yet-defined Portals in pg_cursors view. @ 2024-10-06 20:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2024-10-06 20:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Ignore not-yet-defined Portals in pg_cursors view. pg_cursor() supposed that any Portal it finds in the hash table must have sourceText set up, but there's an edge case where that is not so. A newly-created Portal has sourceText = NULL, and that doesn't change until PortalDefineQuery is called. In SPI_cursor_open_internal, we perform GetCachedPlan between CreatePortal and PortalDefineQuery, and it's possible for user-defined code to execute during that planning and cause a fetch from the pg_cursors view, resulting in a null-pointer-dereference crash. (It looks like the same could happen in exec_bind_message, but I've not tried to provoke a failure there.) I considered trying to fix this by setting sourceText sooner, but there may be instances of this same calling pattern in extensions, and we couldn't be sure they'd get the memo promptly. It seems better to redefine pg_cursor as not showing Portals that have not yet had PortalDefineQuery called on them, which we can do by just skipping them if sourceText is still NULL. (Before a1c692358, pg_cursor would instead return a row with NULL in the statement column. We could revert to that behavior but it doesn't really seem like a better definition, especially since our documentation doesn't suggest that the column could be NULL.) Per report from PetSerAl. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAKygsHTBXLXjwV43kpZa+Cs+XTiaeeJiZdL4cPBm9f4MTdw7wg@mail.gmail.com Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3922c9e9f3de7fee04249c9d65be172432b878cf Modified Files -------------- src/backend/utils/mmgr/portalmem.c | 3 +++ 1 file changed, 3 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2024-10-06 20:04 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us> 2024-10-06 20:04 pgsql: Ignore not-yet-defined Portals in pg_cursors view. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox