From 6117548e328adb029b965484b9aebf5df5c57359 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Fri, 28 Aug 2020 21:46:53 +0200 Subject: [PATCH] fix: disallow empty tags --- CMakeLists.txt | 2 +- src/endpoints/api_v1_tags.c | 10 ++++++++++ src/models/tag.c | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca20ece..a3c7f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project(core - VERSION 0.3.2 + VERSION 0.3.3 LANGUAGES C) add_executable(core src/main.c) diff --git a/src/endpoints/api_v1_tags.c b/src/endpoints/api_v1_tags.c index 96b3d29..2bd4afa 100644 --- a/src/endpoints/api_v1_tags.c +++ b/src/endpoints/api_v1_tags.c @@ -70,6 +70,16 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg 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)) { LOGGER_DEBUG("tag could not be saved\n"); diff --git a/src/models/tag.c b/src/models/tag.c index 589298d..b77367c 100644 --- a/src/models/tag.c +++ b/src/models/tag.c @@ -10,6 +10,11 @@ int 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); int rc;