Fix: Report process uptime and harden the login reserved list

The "启动信息" elapsed time was computed by subtracting a client-formatted
wall-clock string from the master's own local time. Windows clients send their
local time, Linux/Android/macOS send Beijing time, so a host whose clock runs
ahead of the master (UTC+8 clients on a UTC+1 master, a fast CMOS clock) gave a
negative difference that was clamped to 0s — permanently, for that host.

Add RES_UPTIME to the login reserved list: the client reports its process
uptime in seconds, a difference between two readings of the same clock, so
timezone and clock skew cancel out. The master adds the connection's alive
time to get the current value, and keeps the old string path as the fallback
for clients that do not send the field. That fallback now also treats MAC as
Beijing time, which was simply missed.

AddReserved() now goes through one bounds-checked append. The separator used
to be written without any length check (an overflow aborts the client, which
installs no invalid parameter handler), and an over-long value now leaves an
empty slot instead of dropping its separator, so positional lookups cannot
shift.

Verified with an ASan/UBSan test over the encoding boundaries and Debug builds
of the client and the master. The Linux/Android/macOS clients only append the
same field at the end of the list; they were not compiled here.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-08 21:49:20 +01:00
1 parent 2e34e49186
commit 2cbed0dcdf
6 files changed
+149 -38

No files matched your search

+20
View File
@@ -295,6 +295,18 @@ static std::string getExecutablePath()
return "";
}
// 进程已运行秒数(RES_UPTIME)的基准:本文件随进程启动即加载,取加载时刻为起点。
// 与同一块本机墙钟的当前时刻相减,时区不影响结果(下面 getTimeString 固定按 UTC+8
// 格式化,服务端无法据此还原出运行时长)。
static const std::time_t g_processStartTime = std::time(nullptr);
static long long getProcessUptimeSeconds()
{
long long up = static_cast<long long>(std::time(nullptr)) -
static_cast<long long>(g_processStartTime);
return up > 0 ? up : 0;
}
// Get current time string (Beijing time, UTC+8)
static std::string getTimeString()
{
@@ -599,6 +611,14 @@ static void fillLoginInfo(LOGIN_INFOR& info)
}
info.AddReserved(std::to_string(g_myClientID).c_str());
// PID / 文件大小 / TLS:macOS 暂不上报,占位保持位置(服务端按 LOGIN_RES 下标取值,
// 少发一项会让后面所有字段前移)。
info.AddReserved("");
info.AddReserved("");
info.AddReserved("");
// [20] RES_UPTIME:登录时刻的进程已运行秒数,服务端据此算「启动信息」里的时长
info.AddReserved((int)getProcessUptimeSeconds());
// 服务端签名输入:与服务端 AddList 处签名格式一致(startTime + "|" + clientID)
ClientAuth::g_loginMsg = std::string(info.szStartTime) + "|" + std::to_string(g_myClientID);