pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix corner-case uninitialized-variable issues in plpgsql. 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/0fce76b99d21e2c359d8355a9e3bfe4c3e3f17c9 Modified Files -------------- src/pl/plpgsql/src/expected/plpgsql_simple.out | 23 ++++++++ src/pl/plpgsql/src/pl_exec.c | 76 ++++++++++++++++++-------- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 +- src/pl/plpgsql/src/sql/plpgsql_simple.sql | 21 +++++++ 5 files changed, 101 insertions(+), 25 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/85189f54a15ae7d06523ab0bdf1959ff36fdc776 Modified Files -------------- src/pl/plpgsql/src/pl_exec.c | 76 +++++++++++++++++++++++++++++++------------- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 +-- 3 files changed, 57 insertions(+), 25 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4eac891b1a5fa3e65e149423e254abda3cd4b098 Modified Files -------------- src/pl/plpgsql/src/pl_exec.c | 42 +++++++++++++++++++++++++++++++++++++----- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 ++-- 3 files changed, 40 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/dffec69feea8320e21c76355985fcb83e640cd98 Modified Files -------------- src/pl/plpgsql/src/pl_exec.c | 39 +++++++++++++++++++++++++++++++++++---- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/899564e010abf216a90c48d9a1ce3728b8b00266 Modified Files -------------- src/pl/plpgsql/src/expected/plpgsql_simple.out | 23 ++++++++++++ src/pl/plpgsql/src/pl_exec.c | 52 ++++++++++++++++++-------- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 +- src/pl/plpgsql/src/sql/plpgsql_simple.sql | 21 +++++++++++ 5 files changed, 84 insertions(+), 18 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7321d5c3ffc28178bcd72e9e905acfeaa953866b Modified Files -------------- src/pl/plpgsql/src/pl_exec.c | 76 +++++++++++++++++++++++++++++++------------- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 +-- 3 files changed, 57 insertions(+), 25 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix corner-case uninitialized-variable issues in plpgsql. @ 2021-07-20 17:02 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-07-20 17:02 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix corner-case uninitialized-variable issues in plpgsql. If an error was raised during our initial attempt to check whether a successfully-compiled expression is "simple", subsequent calls of exec_stmt_execsql would suppose that stmt->mod_stmt was already computed when it had not been. This could lead to assertion failures in debug builds; in production builds the effect would typically be to act as if INTO STRICT had been specified even when it had not been. Of course that only matters if the subsequent attempt to execute the expression succeeds, so that the problem can only be reached by fixing a failure in some referenced, inline-able SQL function and then retrying the calling plpgsql function in the same session. (There might be even-more-obscure ways to change the expression's behavior without changing the plpgsql function, but that one seems like the only one people would be likely to hit in practice.) The most foolproof way to fix this would be to arrange for exec_prepare_plan to not set expr->plan until we've finished the subsidiary simple-expression check. But it seems hard to do that without creating reference-count leak issues. So settle for documenting the hazard in a comment and fixing exec_stmt_execsql to test separately for whether it's computed stmt->mod_stmt. (That adds a test-and-branch per execution, but hopefully that's negligible in context.) In v11 and up, also fix exec_stmt_call which had a variant of the same issue. Per bug #17113 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/17113-077605ce00e0e7ec@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/d9809bf8694c17e05537c5dd96cde3e67c02d52a Modified Files -------------- src/pl/plpgsql/src/expected/plpgsql_simple.out | 23 ++++++++++++ src/pl/plpgsql/src/pl_exec.c | 52 ++++++++++++++++++-------- src/pl/plpgsql/src/pl_gram.y | 2 +- src/pl/plpgsql/src/plpgsql.h | 4 +- src/pl/plpgsql/src/sql/plpgsql_simple.sql | 21 +++++++++++ 5 files changed, 84 insertions(+), 18 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2021-07-20 17:02 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. Tom Lane <tgl@sss.pgh.pa.us> 2021-07-20 17:02 pgsql: Fix corner-case uninitialized-variable issues in plpgsql. 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