From 60b6f4c62baebd8902b389ad965c9fa0d1f6e83f Mon Sep 17 00:00:00 2001 From: Mahdi Baghbani Date: Sun, 16 Aug 2026 07:14:42 +0000 Subject: [PATCH 1/3] fix(rfb): init perms to avoid uninitialized reads Signed-off-by: Mahdi Baghbani --- common/rfb/VNCSConnectionST.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 27f2fba22..c6113c451 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -98,7 +98,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s, con user[offset] = '\0'; } - bool read, write, owner; + bool read = false, write = false, owner = false; if (!getPerms(read, write, owner)) { accessRights &= ~(WRITER_PERMS | AccessView); } @@ -1242,9 +1242,12 @@ bool VNCSConnectionST::getPerms(bool &read, bool &write, bool &owner) const { bool found = false; if (disablebasicauth) { - // We're running without basicauth + // No basicauth: grant full perms; owner is meaningless without an + // authenticated owner, so report it false (is_owner()/checkOwnerConn() + // would otherwise read it uninitialized). read = true; write = true; + owner = false; return true; } if (user[0]) { @@ -1869,7 +1872,7 @@ void VNCSConnectionST::udpDowngrade(const bool byServer) void VNCSConnectionST::subscribeUnixRelay(const char *name) { - bool read, write, owner; + bool read = false, write = false, owner = false; if (!getPerms(read, write, owner) || !write) { // Need write permissions to subscribe writer()->writeSubscribeUnixRelay(false, "No permissions"); From 9f1c3dfa4073033a9b4695e85897919da9c1b909 Mon Sep 17 00:00:00 2001 From: Mahdi Baghbani Date: Sun, 16 Aug 2026 07:14:49 +0000 Subject: [PATCH 2/3] fix(rfb): add is_owner to session users Signed-off-by: Mahdi Baghbani --- common/rfb/util.cxx | 6 ++++-- common/rfb/util.h | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx index cd150153e..6bee525df 100644 --- a/common/rfb/util.cxx +++ b/common/rfb/util.cxx @@ -686,7 +686,7 @@ namespace rfb { { std::string usersList = "["; bool firstUser = true; - for (const auto&[userName, connectionTime] : users) + for (const auto&[userName, connectionTime, isOwner] : users) { std::string username =userName; time_t connTime = connectionTime; @@ -702,7 +702,9 @@ namespace rfb { userEntry.append(username); userEntry.append( "\", \"connected_since\":\""); userEntry.append(timeStr); - userEntry.append("\"}"); + userEntry.append( "\", \"is_owner\":"); + userEntry.append( isOwner ? "true" : "false"); + userEntry.append("}"); usersList.append(userEntry); } diff --git a/common/rfb/util.h b/common/rfb/util.h index 1dd2ab323..6367092e5 100644 --- a/common/rfb/util.h +++ b/common/rfb/util.h @@ -72,10 +72,12 @@ namespace rfb { struct SessionInfo { std::string userName; time_t connectionTime; - SessionInfo(const std::string& name, const time_t& time) + bool isOwner; + SessionInfo(const std::string& name, const time_t& time, const bool ownerFlag = false) { userName = name; connectionTime = time; + isOwner = ownerFlag; } }; From 6a78742ce1e04ed0f961701f6bfb7b3deea8f447 Mon Sep 17 00:00:00 2001 From: Mahdi Baghbani Date: Sun, 16 Aug 2026 07:14:55 +0000 Subject: [PATCH 3/3] fix(rfb): reset session users on last disconnect Signed-off-by: Mahdi Baghbani --- common/rfb/VNCServerST.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 21dde7b8f..074f06f27 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -819,7 +819,7 @@ std::vector VNCServerST::getSessionUsers() { if (!client->authenticated()) { continue; } - users.push_back(SessionInfo(client->getUsername(),client->getConnectionTime())); + users.push_back(SessionInfo(client->getUsername(), client->getConnectionTime(), client->is_owner())); } return users; } @@ -830,6 +830,11 @@ void VNCServerST::updateSessionUsersList() if (!sessionUsers.empty()) { std::string sessionUsersJson = formatUsersToJson(sessionUsers); apimessager->mainUpdateSessionsInfo(sessionUsersJson); + } else { + // Last disconnect: reset to the canonical empty shape so + // /api/get_sessions signals an empty session (matches the init + // literal in GetAPIMessager.cxx). + apimessager->mainUpdateSessionsInfo("{\"users\":[]}"); } }