fix: disallow empty tags

This commit is contained in:
Tobias Reisinger 2020-08-28 21:46:53 +02:00
parent f98a01f3f0
commit 6117548e32
3 changed files with 16 additions and 1 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7) cmake_minimum_required (VERSION 3.7)
project(core project(core
VERSION 0.3.2 VERSION 0.3.3
LANGUAGES C) LANGUAGES C)
add_executable(core src/main.c) add_executable(core src/main.c)

View file

@ -70,6 +70,16 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg
return; return;
} }
if(strlen(json_tag->valuestring) == 0)
{
LOGGER_DEBUG("tag is empty\n");
cJSON_Delete(json);
static const char content[] = "tag is empty";
endpoint_response_text(response, 400, content, STRLEN(content));
return;
}
if(tag_save(0, json_tag->valuestring)) if(tag_save(0, json_tag->valuestring))
{ {
LOGGER_DEBUG("tag could not be saved\n"); LOGGER_DEBUG("tag could not be saved\n");

View file

@ -10,6 +10,11 @@
int int
tag_save(int id, const char *tag) tag_save(int id, const char *tag)
{ {
if(strlen(tag) == 0)
{
LOGGER_ERR("saving an empty tag is not allowed (id: %d)\n", id);
return 1;
}
LOGGER_DEBUG("saving tag '%s' into database (id: %d)\n", tag, id); LOGGER_DEBUG("saving tag '%s' into database (id: %d)\n", tag, id);
int rc; int rc;