[fix] fix strncpy error

This commit is contained in:
dijunkun
2025-05-28 17:25:39 +08:00
parent f34b55b88a
commit 7ea26854af
2 changed files with 5 additions and 3 deletions

View File

@@ -159,9 +159,11 @@ int Render::ConnectTo(const std::string &remote_id, const char *password,
auto props = client_properties_[remote_id]; auto props = client_properties_[remote_id];
if (!props->connection_established_) { if (!props->connection_established_) {
props->remember_password_ = remember_password; props->remember_password_ = remember_password;
if (strcmp(password, "") != 0) { if (strcmp(password, "") != 0 &&
strcmp(password, props->remote_password_) != 0) {
strncpy(props->remote_password_, password, strncpy(props->remote_password_, password,
sizeof(props->remote_password_)); sizeof(props->remote_password_) - 1);
props->remote_password_[sizeof(props->remote_password_) - 1] = '\0';
} }
ret = JoinConnection(props->peer_, remote_id.c_str(), password); ret = JoinConnection(props->peer_, remote_id.c_str(), password);
if (0 == ret) { if (0 == ret) {