ecpg: check return value of replace_variables()
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Fri, 17 Oct 2025 08:03:15 +0000 (10:03 +0200)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Fri, 17 Oct 2025 08:03:15 +0000 (10:03 +0200)
The function returns false if it fails to allocate memory, so
make sure to check the return value in callsites.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CAJ7c6TNPrU8ZxgdfN3PyGY1tzo0bgszx+KkqW0Z7zt3heyC1GQ@mail.gmail.com

src/interfaces/ecpg/ecpglib/prepare.c

index 06f0135813b371d06fee38828f32e14e8fbb04c0..4b1ae83950679b4f5b27d01ac9cfbf9163d7f9fc 100644 (file)
@@ -200,7 +200,13 @@ prepare_common(int lineno, struct connection *con, const char *name, const char
    stmt->inlist = stmt->outlist = NULL;
 
    /* if we have C variables in our statement replace them with '?' */
-   replace_variables(&(stmt->command), lineno);
+   if (!replace_variables(&(stmt->command), lineno))
+   {
+       ecpg_free(stmt->command);
+       ecpg_free(stmt);
+       ecpg_free(this);
+       return false;
+   }
 
    /* add prepared statement to our list */
    this->name = ecpg_strdup(name, lineno, NULL);