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

+7
View File
@@ -543,6 +543,10 @@ int DataProcess(void* /*user*/, PBYTE szBuffer, ULONG ulLength)
}
// ------------------------------------------------------------------ 网络主线程
// 进程已运行秒数(RES_UPTIME)的单调基准。steady_clock 在 Android 上对应
// CLOCK_MONOTONIC,不受系统时间调整影响;库加载即开始计时。
static const auto g_processStartMono = std::chrono::steady_clock::now();
static void ConnectionThread()
{
LOGI("ConnectionThread → %s:%d", g_serverIp.c_str(), g_serverPort);
@@ -585,6 +589,9 @@ static void ConnectionThread()
logInfo.AddReserved(std::to_string(g_myClientID).c_str());
logInfo.AddReserved((int)getpid()); // PID
logInfo.AddReserved(FormatFileSize(GetFileSize(g_apkPath)).c_str()); // 文件大小
logInfo.AddReserved(0); // [19] RES_TLS(Android 无 TLS 通道)
logInfo.AddReserved((int)std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::steady_clock::now() - g_processStartMono).count()); // [20] RES_UPTIME
ClientAuth::g_loginMsg = std::string(logInfo.szStartTime) + "|" + std::to_string(g_myClientID);
LOGI("ClientID=%" PRIu64, g_myClientID);