aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/preproc
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2014-03-01 22:14:14 -0500
committerStephen Frost <sfrost@snowman.net>2014-03-01 22:14:14 -0500
commitb1aebbb6a86e96d7b8f3035ac730dfc24652496c (patch)
tree838f5464cf1a76766cf182ac4e812f3056297812 /src/interfaces/ecpg/preproc
parent9662143f0c35d64d7042fbeaf879df8f0b54be32 (diff)
downloadpostgresql-b1aebbb6a86e96d7b8f3035ac730dfc24652496c.tar.gz
postgresql-b1aebbb6a86e96d7b8f3035ac730dfc24652496c.zip
Various Coverity-spotted fixes
A number of issues were identified by the Coverity scanner and are addressed in this patch. None of these appear to be security issues and many are mostly cosmetic changes. Short comments for each of the changes follows. Correct the semi-colon placement in be-secure.c regarding SSL retries. Remove a useless comparison-to-NULL in proc.c (value is dereferenced prior to this check and therefore can't be NULL). Add checking of chmod() return values to initdb. Fix a couple minor memory leaks in initdb. Fix memory leak in pg_ctl- involves free'ing the config file contents. Use an int to capture fgetc() return instead of an enum in pg_dump. Fix minor memory leaks in pg_dump. (note minor change to convertOperatorReference()'s API) Check fclose()/remove() return codes in psql. Check fstat(), find_my_exec() return codes in psql. Various ECPG memory leak fixes. Check find_my_exec() return in ECPG. Explicitly ignore pqFlush return in libpq error-path. Change PQfnumber() to avoid doing an strdup() when no changes required. Remove a few useless check-against-NULL's (value deref'd beforehand). Check rmtree(), malloc() results in pg_regress. Also check get_alternative_expectfile() return in pg_regress.
Diffstat (limited to 'src/interfaces/ecpg/preproc')
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c6
-rw-r--r--src/interfaces/ecpg/preproc/type.c76
-rw-r--r--src/interfaces/ecpg/preproc/variable.c5
3 files changed, 66 insertions, 21 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index cd110f6b488..339ca8821ab 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -138,7 +138,11 @@ main(int argc, char *const argv[])
progname = get_progname(argv[0]);
- find_my_exec(argv[0], my_exec_path);
+ if (find_my_exec(argv[0], my_exec_path) < 0)
+ {
+ fprintf(stderr, _("%s: could not locate my own executable path\n"), argv[0]);
+ return (ILLEGAL_OPTION);
+ }
output_filename = NULL;
while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h?", ecpg_options, NULL)) != -1)
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index c24b4c2fbcd..2982cb62049 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -308,7 +308,11 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
if (ind_type != NULL)
{
if (ind_type->type == ECPGt_NO_INDICATOR)
- ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, mm_strdup("-1"), NULL, ind_prefix, 0);
+ {
+ char *str_neg_one = mm_strdup("-1");
+ ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, str_neg_one, NULL, ind_prefix, 0);
+ free(str_neg_one);
+ }
else
{
ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
@@ -318,37 +322,71 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
}
break;
case ECPGt_struct:
- if (indicator_set && ind_type->type != ECPGt_struct)
- mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
+ {
+ char *str_one = mm_strdup("1");
- ECPGdump_a_struct(o, name, ind_name, mm_strdup("1"), type, ind_type, prefix, ind_prefix);
+ if (indicator_set && ind_type->type != ECPGt_struct)
+ mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
+
+ ECPGdump_a_struct(o, name, ind_name, str_one, type, ind_type, prefix, ind_prefix);
+ free(str_one);
+ }
break;
case ECPGt_union: /* cannot dump a complete union */
base_yyerror("type of union has to be specified");
break;
case ECPGt_char_variable:
- if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
+ {
+ /* Allocate for each, as there are code-paths where the values get stomped on. */
+ char *str_varchar_one = mm_strdup("1");
+ char *str_arr_one = mm_strdup("1");
+ char *str_neg_one = mm_strdup("-1");
+
+ if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
- ECPGdump_a_simple(o, name, type->type, mm_strdup("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("1"), struct_sizeof, prefix, 0);
- if (ind_type != NULL)
- ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("-1"), ind_struct_sizeof, ind_prefix, 0);
+ ECPGdump_a_simple(o, name, type->type, str_varchar_one, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : str_arr_one, struct_sizeof, prefix, 0);
+ if (ind_type != NULL)
+ ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : str_neg_one, ind_struct_sizeof, ind_prefix, 0);
+
+ free(str_varchar_one);
+ free(str_arr_one);
+ free(str_neg_one);
+ }
break;
case ECPGt_descriptor:
- if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
+ {
+ /* Allocate for each, as there are code-paths where the values get stomped on. */
+ char *str_neg_one = mm_strdup("-1");
+ char *ind_type_neg_one = mm_strdup("-1");
+
+ if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
- ECPGdump_a_simple(o, name, type->type, NULL, mm_strdup("-1"), NULL, prefix, 0);
- if (ind_type != NULL)
- ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, mm_strdup("-1"), NULL, ind_prefix, 0);
+ ECPGdump_a_simple(o, name, type->type, NULL, str_neg_one, NULL, prefix, 0);
+ if (ind_type != NULL)
+ ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, ind_type_neg_one, NULL, ind_prefix, 0);
+
+ free(str_neg_one);
+ free(ind_type_neg_one);
+ }
break;
default:
- if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
- mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
+ {
+ /* Allocate for each, as there are code-paths where the values get stomped on. */
+ char *str_neg_one = mm_strdup("-1");
+ char *ind_type_neg_one = mm_strdup("-1");
+
+ if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
+ mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
- ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("-1"), struct_sizeof, prefix, type->counter);
- if (ind_type != NULL)
- ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : mm_strdup("-1"), ind_struct_sizeof, ind_prefix, 0);
+ ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : str_neg_one, struct_sizeof, prefix, type->counter);
+ if (ind_type != NULL)
+ ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : ind_type_neg_one, ind_struct_sizeof, ind_prefix, 0);
+
+ free(str_neg_one);
+ free(ind_type_neg_one);
+ }
break;
}
}
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index cc923a797bc..d762286b94f 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -437,6 +437,7 @@ remove_variable_from_list(struct arguments ** list, struct variable * var)
void
dump_variables(struct arguments * list, int mode)
{
+ char *str_zero = mm_strdup("0");
if (list == NULL)
return;
@@ -450,11 +451,13 @@ dump_variables(struct arguments * list, int mode)
/* Then the current element and its indicator */
ECPGdump_a_type(yyout, list->variable->name, list->variable->type, list->variable->brace_level,
list->indicator->name, list->indicator->type, list->indicator->brace_level,
- NULL, NULL, mm_strdup("0"), NULL, NULL);
+ NULL, NULL, str_zero, NULL, NULL);
/* Then release the list element. */
if (mode != 0)
free(list);
+
+ free(str_zero);
}
void