From 913c314b312992386b6b514ef42203914bc3ad23 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Mon, 2 Oct 2023 21:56:59 +0000 Subject: [PATCH] server: Use memcpy instead of strncpy for username/password This fixed zero-termination error --- src/server.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/server.c b/src/server.c index d8a47c7..0387b49 100644 --- a/src/server.c +++ b/src/server.c @@ -755,11 +755,10 @@ static int on_rsa_aes_credentials(struct nvnc_client* client) char username[256]; char password[256]; - strncpy(username, (const char*)(msg + 1), username_len + 1); - username[sizeof(username) - 1] = '\0'; - strncpy(password, (const char*)(msg + 2 + username_len), - password_len + 1); - password[sizeof(password) - 1] = '\0'; + memcpy(username, (const char*)(msg + 1), username_len); + username[username_len] = '\0'; + memcpy(password, (const char*)(msg + 2 + username_len), password_len); + password[password_len] = '\0'; if (server->auth_fn(username, password, server->auth_ud)) { nvnc_log(NVNC_LOG_INFO, "User \"%s\" authenticated", username);