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:
1 parent
2e34e49186
commit
2cbed0dcdf
6 files changed
+149
-38
No files matched your search
@@ -1048,6 +1048,15 @@ std::string getProcessStartTime()
|
||||
return ToPekingTimeAsString(&g_processStartTime);
|
||||
}
|
||||
|
||||
// 进程已运行秒数(RES_UPTIME):与 getProcessStartTime 同源,都是本机墙钟,相减后
|
||||
// 时区不影响结果。服务端用它算运行时长,就不必拿自己的时刻去减别的机器的时刻了。
|
||||
long long getProcessUptimeSeconds()
|
||||
{
|
||||
long long up = static_cast<long long>(std::time(nullptr)) -
|
||||
static_cast<long long>(g_processStartTime);
|
||||
return up > 0 ? up : 0;
|
||||
}
|
||||
|
||||
// 获取 CPU 核心数
|
||||
int getCPUCores()
|
||||
{
|
||||
@@ -1973,6 +1982,7 @@ int main(int argc, char* argv[])
|
||||
logInfo.AddReserved((int)getpid()); // [17] RES_PID
|
||||
logInfo.AddReserved(getFileSize(exePath).c_str()); // [18] RES_FILESIZE
|
||||
logInfo.AddReserved(TlsEnabled() ? 1 : 0); // [19] RES_TLS(有信任锚即 1)
|
||||
logInfo.AddReserved((int)getProcessUptimeSeconds()); // [20] RES_UPTIME(登录时已运行秒数)
|
||||
|
||||
// 服务端签名输入:与服务端 AddList 处签名格式一致(startTime + "|" + clientID)
|
||||
ClientAuth::g_loginMsg = std::string(logInfo.szStartTime) + "|" + std::to_string(g_myClientID);
|
||||
|
||||
Reference in new issue
Block a user