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

+27
View File
@@ -126,6 +126,29 @@ std::string getProcessTime()
return buffer;
}
// 进程已运行秒数(RES_UPTIME)。创建时刻和「现在」都取自本机同一块系统时钟,相减
// 会把时区和整机时钟偏移一起抵消——服务端拿自己本地时间去减 szStartTime 时做不到
// 这一点,时钟领先的主机会被算成负数、钳成恒定的 0s。
// 取不到创建时刻时返回空串,服务端据此退回按 szStartTime 计算。
std::string getProcessUptime()
{
FILETIME creationTime, exitTime, kernelTime, userTime;
if (!GetProcessTimes(GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime))
return "";
ULARGE_INTEGER created, now;
created.LowPart = creationTime.dwLowDateTime;
created.HighPart = creationTime.dwHighDateTime;
FILETIME nowFt;
GetSystemTimeAsFileTime(&nowFt);
now.LowPart = nowFt.dwLowDateTime;
now.HighPart = nowFt.dwHighDateTime;
if (now.QuadPart <= created.QuadPart)
return "0";
return std::to_string((now.QuadPart - created.QuadPart) / 10000000ULL);
}
int getOSBits()
{
SYSTEM_INFO si;
@@ -479,6 +502,10 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, CONNECT_ADDRESS& conn, const std::string
// (设计文档 §3.7)。
LoginInfor.AddReserved(tlsOnWire ? 1 : 0);
// [20] RES_UPTIME:登录时刻的进程已运行秒数,服务端用它算「启动信息」里的时长,
// 不再依赖跨机器的墙钟比较(见 getProcessUptime)。
LoginInfor.AddReserved(getProcessUptime().c_str());
// 本机是不是靠「生成时内嵌的锚」在加密:只有这种情况下,关掉服务端 TLS 才会把它
// 锁死(在线可下发取消、离线永久失联,见 §3.5)。服务端据此在「取消 TLS」前提示。
// 必须按连接取(IsTlsAnchorEmbedded):分享/并行实例向上线到另一台主控时用的是对方