From cb409757c33aa8ac8e0bc473ac4e8f6430f0f491 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 20 Dec 2022 23:54:50 +0100 Subject: [PATCH] Use String length() instead of size() in QueryBuilder, also guard against overindexing. --- modules/database/query_builder.cpp | 6 ++++-- modules/database_sqlite/sqlite3_query_builder.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/database/query_builder.cpp b/modules/database/query_builder.cpp index eab37ec1f..d228cca33 100644 --- a/modules/database/query_builder.cpp +++ b/modules/database/query_builder.cpp @@ -201,7 +201,9 @@ QueryBuilder *QueryBuilder::order_by(const String &col) { } QueryBuilder *QueryBuilder::corder_by() { - query_result[query_result.size() - 2] = ' '; + ERR_FAIL_COND_V(query_result.length() <= 2, this); + + query_result[query_result.length() - 2] = ' '; return this; } @@ -212,7 +214,7 @@ QueryBuilder *QueryBuilder::order_by_add_col(const String &col) { } QueryBuilder *QueryBuilder::asc(const String &col) { if (col == "") { - query_result += "ASC,"; + query_result += "ASC, "; } else { query_result += col + " ASC, "; } diff --git a/modules/database_sqlite/sqlite3_query_builder.cpp b/modules/database_sqlite/sqlite3_query_builder.cpp index 359ef142e..a2f5a9f56 100644 --- a/modules/database_sqlite/sqlite3_query_builder.cpp +++ b/modules/database_sqlite/sqlite3_query_builder.cpp @@ -21,12 +21,16 @@ QueryBuilder *SQLite3QueryBuilder::del() { } QueryBuilder *SQLite3QueryBuilder::cvalues() { + ERR_FAIL_COND_V(query_result.length() <= 2, this); + query_result[query_result.length() - 2] = ' '; query_result += ") "; return this; } QueryBuilder *SQLite3QueryBuilder::next_value() { + ERR_FAIL_COND_V(query_result.length() <= 2, this); + query_result[query_result.length() - 2] = ' '; query_result += "), ("; @@ -208,6 +212,8 @@ QueryBuilder *SQLite3QueryBuilder::sets() { return this; } QueryBuilder *SQLite3QueryBuilder::cset() { + ERR_FAIL_COND_V(query_result.length() <= 2, this); + query_result[query_result.length() - 2] = ' '; return this;