diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-26 10:39:11 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-26 10:39:11 -0400 |
commit | 39fe881d3cf315d8d2ea9ee4ea1e3e39a82d5cc7 (patch) | |
tree | 0ec4dbeae09e426312e9916e2dd34e1ab0a02957 /src/interfaces/ecpg/ecpglib/execute.c | |
parent | 331695a4d9ca40864240aca721dc588a206ff395 (diff) | |
download | postgresql-39fe881d3cf315d8d2ea9ee4ea1e3e39a82d5cc7.tar.gz postgresql-39fe881d3cf315d8d2ea9ee4ea1e3e39a82d5cc7.zip |
Fix more thinkos in new ECPG "PREPARE AS" code.
ecpg_build_params() failed to check for ecpg_alloc failure in one
newly-added code path, and leaked a temporary string in another path.
Errors in commit a1dc6ab46, spotted by Coverity.
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/execute.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 6dbf2fa9e01..3c0294e98aa 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1454,13 +1454,21 @@ ecpg_build_params(struct statement *stmt) if (stmt->statement_type == ECPGst_prepare || stmt->statement_type == ECPGst_exec_with_exprlist) { - /* Add double quote both side for embedding statement name. */ - char *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1, stmt->lineno); + /* Need to double-quote the inserted statement name. */ + char *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1, + stmt->lineno); + if (!str) + { + ecpg_free(tobeinserted); + ecpg_free_params(stmt, false); + return false; + } sprintf(str, "\"%s\"", tobeinserted); ecpg_free(tobeinserted); tobeinserted = str; } + if (!insert_tobeinserted(position, 2, stmt, tobeinserted)) { ecpg_free_params(stmt, false); @@ -1470,11 +1478,13 @@ ecpg_build_params(struct statement *stmt) } else if (stmt->statement_type == ECPGst_exec_with_exprlist) { - if (binary_format) { - char *p = convert_bytea_to_string(tobeinserted, binary_length, stmt->lineno); + char *p = convert_bytea_to_string(tobeinserted, + binary_length, + stmt->lineno); + ecpg_free(tobeinserted); if (!p) { ecpg_free_params(stmt, false); |