diff options
author | Michael Meskes <meskes@postgresql.org> | 2019-02-26 10:56:54 +0100 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2019-02-26 10:56:54 +0100 |
commit | 0cc0507940c1cf4153fc25c8f6f4f75adada86d0 (patch) | |
tree | 1abde3629acaab656a41890c13e09cb77bfeee0d | |
parent | 6e52209eb1f830552a5ec220c2bfc3b517535837 (diff) | |
download | postgresql-0cc0507940c1cf4153fc25c8f6f4f75adada86d0.tar.gz postgresql-0cc0507940c1cf4153fc25c8f6f4f75adada86d0.zip |
Hopefully fixing memory handling issues in ecpglib that Coverity found.
-rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 0c147b77cc9..8e61339ae30 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1073,9 +1073,14 @@ print_param_value(char *value, int len, int is_binary, int lineno, int nth) else { value_s = ecpg_alloc(ecpg_hex_enc_len(len)+1, lineno); - ecpg_hex_encode(value, len, value_s); - value_s[ecpg_hex_enc_len(len)] = '\0'; - malloced = true; + if (value_s != NULL) + { + ecpg_hex_encode(value, len, value_s); + value_s[ecpg_hex_enc_len(len)] = '\0'; + malloced = true; + } + else + value_s = "no memory for logging of parameter"; } ecpg_log("ecpg_free_params on line %d: parameter %d = %s\n", @@ -1134,7 +1139,7 @@ insert_tobeinserted(int position, int ph_len, struct statement *stmt, char *tobe ecpg_free(stmt->command); stmt->command = newcopy; - ecpg_free((char *) tobeinserted); + ecpg_free(tobeinserted); return true; } @@ -1400,6 +1405,7 @@ ecpg_build_params(struct statement *stmt) ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); ecpg_free_params(stmt, false); + ecpg_free(tobeinserted); return false; } @@ -1436,33 +1442,28 @@ ecpg_build_params(struct statement *stmt) } else { - char **paramvalues; - int *paramlengths; - int *paramformats; - - if (!(paramvalues = (char **) ecpg_realloc(stmt->paramvalues, sizeof(char *) * (stmt->nparams + 1), stmt->lineno))) + if (!(stmt->paramvalues = (char **) ecpg_realloc(stmt->paramvalues, sizeof(char *) * (stmt->nparams + 1), stmt->lineno))) { ecpg_free_params(stmt, false); + ecpg_free(tobeinserted); return false; } - if (!(paramlengths = (int *) ecpg_realloc(stmt->paramlengths, sizeof(int) * (stmt->nparams + 1), stmt->lineno))) + stmt->paramvalues[stmt->nparams] = tobeinserted; + + if (!(stmt->paramlengths = (int *) ecpg_realloc(stmt->paramlengths, sizeof(int) * (stmt->nparams + 1), stmt->lineno))) { ecpg_free_params(stmt, false); return false; } - if (!(paramformats = (int *) ecpg_realloc(stmt->paramformats, sizeof(int) * (stmt->nparams + 1), stmt->lineno))) + stmt->paramlengths[stmt->nparams] = binary_length; + + if (!(stmt->paramformats = (int *) ecpg_realloc(stmt->paramformats, sizeof(int) * (stmt->nparams + 1), stmt->lineno))) { ecpg_free_params(stmt, false); return false; } - + stmt->paramformats[stmt->nparams] = (binary_format ? 1 : 0); stmt->nparams++; - stmt->paramvalues = paramvalues; - stmt->paramlengths = paramlengths; - stmt->paramformats = paramformats; - stmt->paramvalues[stmt->nparams - 1] = tobeinserted; - stmt->paramlengths[stmt->nparams - 1] = binary_length; - stmt->paramformats[stmt->nparams - 1] = (binary_format ? 1 : 0); /* let's see if this was an old style placeholder */ if (stmt->command[position] == '?') |