Skip to content

Commit e1c2c18

Browse files
committed
Fix crash when invalid 'pkey' is specified in configuration file
1 parent 23a61cd commit e1c2c18

File tree

4 files changed

+7
-49
lines changed

4 files changed

+7
-49
lines changed

src/ows/ows_psql.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,6 @@ PGresult * ows_psql_exec(ows *o, const char *sql)
7070
}
7171

7272

73-
/*
74-
* Return the column number of the id column from table matching layer name
75-
* (needed in wfs_get_feature only)
76-
*/
77-
int ows_psql_column_number_id_column(ows * o, buffer * layer_name)
78-
{
79-
ows_layer_node *ln = NULL;
80-
81-
assert(o);
82-
assert(o->layers);
83-
assert(layer_name);
84-
85-
for (ln = o->layers->first ; ln ; ln = ln->next)
86-
if (ln->layer->name && ln->layer->storage
87-
&& !strcmp(ln->layer->name->buf, layer_name->buf))
88-
return ln->layer->storage->pkey_column_number;
89-
90-
return -1;
91-
}
92-
93-
9473
/*
9574
* Return geometry columns from the table matching layer name
9675
*/

src/ows/ows_storage.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ ows_layer_storage * ows_layer_storage_init()
4444
storage->pkey = NULL;
4545
storage->pkey_sequence = NULL;
4646
storage->pkey_default = NULL;
47-
storage->pkey_column_number = -1;
4847
storage->attributes = array_init();
4948
storage->not_null_columns = NULL;
5049

@@ -103,8 +102,6 @@ void ows_layer_storage_flush(ows_layer_storage * storage, FILE * output)
103102
fprintf(output, "\n");
104103
}
105104

106-
fprintf(output, "pkey_column_number: %i\n", storage->pkey_column_number);
107-
108105
if (storage->pkey_sequence) {
109106
fprintf(output, "pkey_sequence: ");
110107
buffer_flush(storage->pkey_sequence, output);
@@ -225,28 +222,6 @@ static void ows_storage_fill_pkey(ows * o, ows_layer * l)
225222
buffer_empty(sql);
226223
PQclear(res);
227224

228-
/* Retrieve the Pkey column number */
229-
buffer_add_str(sql, "SELECT a.attnum FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n");
230-
buffer_add_str(sql, " WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND n.nspname='");
231-
buffer_copy(sql, l->storage->schema);
232-
buffer_add_str(sql, "' AND c.relname='");
233-
buffer_copy(sql, l->storage->table);
234-
buffer_add_str(sql, "' AND a.attname='");
235-
buffer_copy(sql, l->storage->pkey);
236-
buffer_add_str(sql, "'");
237-
res = ows_psql_exec(o, sql->buf);
238-
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
239-
PQclear(res);
240-
buffer_free(sql);
241-
ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED, "Unable to find pkey column number.", "pkey_column number");
242-
return;
243-
}
244-
245-
/* -1 because column number start at 1 */
246-
l->storage->pkey_column_number = atoi(PQgetvalue(res, 0, 0)) - 1;
247-
buffer_empty(sql);
248-
PQclear(res);
249-
250225
/* Now try to find a sequence related to this Pkey */
251226
buffer_add_str(sql, "SELECT pg_get_serial_sequence('");
252227
buffer_copy(sql, l->storage->schema);
@@ -258,10 +233,16 @@ static void ows_storage_fill_pkey(ows * o, ows_layer * l)
258233

259234
res = ows_psql_exec(o, sql->buf);
260235
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
236+
char message[256];
237+
snprintf(message, sizeof(message),
238+
"Unable to use pg_get_serial_sequence(%s, %s, %s).",
239+
l->storage->schema->buf,
240+
l->storage->table->buf,
241+
l->storage->pkey->buf);
261242
PQclear(res);
262243
buffer_free(sql);
263244
ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED,
264-
"Unable to use pg_get_serial_sequence.", "pkey_sequence retrieve");
245+
message, "pkey_sequence retrieve");
265246
return;
266247
}
267248

src/ows_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ buffer *ows_psql_id_column (ows * o, buffer * layer_name);
185185
buffer *ows_psql_column_constraint_name(ows * o, buffer * column_name, buffer * table_name);
186186
list *ows_psql_column_check_constraint(ows * o, buffer * constraint_name);
187187
buffer *ows_psql_column_character_maximum_length(ows * o, buffer * column_name, buffer * table_name);
188-
int ows_psql_column_number_id_column(ows * o, buffer * layer_name);
189188
bool ows_psql_is_geometry_column (ows * o, buffer * layer_name, buffer * column);
190189
bool ows_psql_is_geometry_valid(ows * o, buffer * geom);
191190
list *ows_psql_not_null_properties (ows * o, buffer * layer_name);

src/ows_struct.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ typedef struct Ows_layer_storage {
107107
buffer * pkey;
108108
buffer * pkey_sequence;
109109
buffer * pkey_default;
110-
int pkey_column_number;
111110
bool is_geographic; /* true for a geographic CRS (or a compound CRS
112111
whose base is geographic), false for a projected
113112
CRS (or a compound CRS whose base is projected) */

0 commit comments

Comments
 (0)