From a1e1df0886b6a17d6a1bc3788f6c48f94166c2b8 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 22 Nov 2024 12:25:24 +0100 Subject: [PATCH] Fix: Rollback on create_credential privkey error If the private key checks in create_credential fail, the SQL transaction is now rolled back. This fixes SQL transaction errors and possible incomplete credentials being created if there are multiple GMP commands per connection and one of them is create_credential failing because of the private key. --- src/manage_sql.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 945ae9aa0..66dafb594 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -35916,7 +35916,10 @@ create_credential (const char* name, const char* comment, const char* login, if (key_private) key_private_truncated = truncate_private_key (key_private); else - return 3; + { + sql_rollback (); + return 3; + } generated_key_public = gvm_ssh_public_from_private (key_private_truncated @@ -35926,6 +35929,7 @@ create_credential (const char* name, const char* comment, const char* login, if (generated_key_public == NULL) { g_free (key_private_truncated); + sql_rollback (); return 3; } g_free (generated_key_public);