Skip to content

Commit 39fe881

Browse files
committed
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 a1dc6ab, spotted by Coverity.
1 parent 331695a commit 39fe881

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,13 +1454,21 @@ ecpg_build_params(struct statement *stmt)
14541454
if (stmt->statement_type == ECPGst_prepare ||
14551455
stmt->statement_type == ECPGst_exec_with_exprlist)
14561456
{
1457-
/* Add double quote both side for embedding statement name. */
1458-
char *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1, stmt->lineno);
1457+
/* Need to double-quote the inserted statement name. */
1458+
char *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1,
1459+
stmt->lineno);
14591460

1461+
if (!str)
1462+
{
1463+
ecpg_free(tobeinserted);
1464+
ecpg_free_params(stmt, false);
1465+
return false;
1466+
}
14601467
sprintf(str, "\"%s\"", tobeinserted);
14611468
ecpg_free(tobeinserted);
14621469
tobeinserted = str;
14631470
}
1471+
14641472
if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
14651473
{
14661474
ecpg_free_params(stmt, false);
@@ -1470,11 +1478,13 @@ ecpg_build_params(struct statement *stmt)
14701478
}
14711479
else if (stmt->statement_type == ECPGst_exec_with_exprlist)
14721480
{
1473-
14741481
if (binary_format)
14751482
{
1476-
char *p = convert_bytea_to_string(tobeinserted, binary_length, stmt->lineno);
1483+
char *p = convert_bytea_to_string(tobeinserted,
1484+
binary_length,
1485+
stmt->lineno);
14771486

1487+
ecpg_free(tobeinserted);
14781488
if (!p)
14791489
{
14801490
ecpg_free_params(stmt, false);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy