From adf751fb219d4e288d92dac1f615c6571da93e29 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 6 Nov 2019 18:26:39 +0200 Subject: [PATCH 1/2] Also check IDs when setting prefs for CREATE_CONFIG --- src/gmp_configs.c | 54 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/src/gmp_configs.c b/src/gmp_configs.c index f40c737cf..d5ebc836b 100644 --- a/src/gmp_configs.c +++ b/src/gmp_configs.c @@ -177,6 +177,30 @@ attr_or_null (entity_t entity, const gchar *name) return NULL; } +/** + * @brief Cleanup preferences array. + * + * @param[in] import_preferences Import preferences. + */ +static void +cleanup_import_preferences (array_t *import_preferences) +{ + if (import_preferences) + { + guint index; + + for (index = 0; index < import_preferences->len; index++) + { + preference_t *pref; + pref = (preference_t*) g_ptr_array_index (import_preferences, + index); + if (pref) + preference_free (pref); + } + g_ptr_array_free (import_preferences, TRUE); + } +} + /** * @brief Execute command. * @@ -347,7 +371,19 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) __FUNCTION__, preference_nvt_oid, preference_name); - new_preference = NULL; + + SEND_TO_CLIENT_OR_FAIL + (XML_ERROR_SYNTAX ("create_config", + "Error in PREFERENCES element.")); + log_event_fail ("config", "Scan config", NULL, "created"); + + /* Cleanup. */ + + cleanup_import_preferences (import_preferences); + array_free (import_nvt_selectors); + + create_config_reset (); + return; } } else @@ -448,21 +484,7 @@ create_config_run (gmp_parser_t *gmp_parser, GError **error) /* Cleanup. */ - if (import_preferences) - { - guint index; - - for (index = 0; index < import_preferences->len; index++) - { - preference_t *pref; - pref = (preference_t*) g_ptr_array_index (import_preferences, - index); - if (pref) - preference_free (pref); - } - g_ptr_array_free (import_preferences, TRUE); - } - + cleanup_import_preferences (import_preferences); array_free (import_nvt_selectors); create_config_reset (); From 5f2071b34f78856fa7726554452fe30a06a34879 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Wed, 6 Nov 2019 18:27:56 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae11a49c1..7505941e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add option --optimize migrate-relay-sensors [#827](https://github.com/greenbone/gvmd/pull/827) - Add host_id filter for tls_certificates [#835](https://github.com/greenbone/gvmd/pull/835) - Allow use of public key auth in SCP alert [#845](https://github.com/greenbone/gvmd/pull/845) -- Refuse to import config with missing NVT preference ID [#856](https://github.com/greenbone/gvmd/pull/856) +- Refuse to import config with missing NVT preference ID [#856](https://github.com/greenbone/gvmd/pull/856) [#860](https://github.com/greenbone/gvmd/pull/860) ### Changed - Extend command line options for managing scanners [#815](https://github.com/greenbone/gvmd/pull/815)