mirror of https://git.48k.eu/ogserver
#915 Avoid duplicate db entries in /create/image
/create/image adds an entry to the database for the given partition image created when payload contains a "description" attribute. This insertion into the database is lacking a check for duplicates, which are not supported for the images table. Add a prior duplicate check before inserting. Exit with -1 code if an image with the same name is found.master v1.2.0
parent
8015f85b04
commit
11d6e84b8e
18
src/dbi.c
18
src/dbi.c
|
@ -134,6 +134,24 @@ int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
|
|||
const char *msglog;
|
||||
dbi_result result;
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT nombreca FROM imagenes WHERE nombreca = '%s'",
|
||||
image->name);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
__func__, __LINE__, msglog);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dbi_result_next_row(result)) {
|
||||
syslog(LOG_ERR, "image creation attempt with already used image name (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
dbi_result_free(result);
|
||||
return -1;
|
||||
}
|
||||
dbi_result_free(result);
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"INSERT INTO imagenes (nombreca, "
|
||||
"descripcion, "
|
||||
|
|
Loading…
Reference in New Issue