From dc6db358f4d7c3728a66daddd3c01231608c083d Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 6 Oct 2025 01:06:41 +0500 Subject: [PATCH] Few fixes --- lib/PgSQL_Connection.cpp | 8 +++----- lib/PgSQL_Protocol.cpp | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/PgSQL_Connection.cpp b/lib/PgSQL_Connection.cpp index 7af1ff19b..7abcd8550 100644 --- a/lib/PgSQL_Connection.cpp +++ b/lib/PgSQL_Connection.cpp @@ -129,15 +129,13 @@ bool PgSQL_Connection_userinfo::set_dbname(const char* db) { const int new_db_len = db ? strlen(db) : 0; const int old_db_len = dbname ? strlen(dbname) : 0; - if (old_db_len == 0 || - old_db_len != new_db_len || - strncmp(db, dbname, new_db_len)) { + if (old_db_len == 0 || old_db_len != new_db_len || strcmp(db, dbname)) { if (dbname) { free(dbname); } dbname = (char*)malloc(new_db_len + 1); - memcpy(dbname, db, new_db_len); - dbname[new_db_len] = 0; + // Copy string including null terminator + memcpy(dbname, db, new_db_len + 1); compute_hash(); return true; } diff --git a/lib/PgSQL_Protocol.cpp b/lib/PgSQL_Protocol.cpp index 23b5fca6e..4f4e87cbd 100644 --- a/lib/PgSQL_Protocol.cpp +++ b/lib/PgSQL_Protocol.cpp @@ -1097,8 +1097,7 @@ EXECUTION_STATE PgSQL_Protocol::process_handshake_response_packet(unsigned char* if (i == PGSQL_NAME_LAST_LOW_WM) continue; // using internal_variable_name because it follows the lowercase naming convention - if (strncmp(param_key.c_str(), pgsql_tracked_variables[i].internal_variable_name, - strlen(pgsql_tracked_variables[i].internal_variable_name)) == 0) { + if (strcmp(param_key.c_str(), pgsql_tracked_variables[i].internal_variable_name) == 0) { idx = i; break; }