fix(svcd): remove_svc_idx memmove 左移后 argv[] 同源悬垂 — 对移动区间每槽 svc_rebuild_argv 重定位(agent-167 诚实的同类bug, 一并根治)
This commit is contained in:
1 parent
408b165ba3
commit
4cf8e1e6ca
2 files changed
+9
-2
No files matched your search
Binary file not shown.
@@ -366,9 +366,16 @@ static int find_svc(const char *name)
|
||||
static void remove_svc_idx(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= g_nsvc) return;
|
||||
if (g_nsvc - idx - 1 > 0)
|
||||
int moved = g_nsvc - idx - 1;
|
||||
if (moved > 0) {
|
||||
memmove(&g_svcs[idx], &g_svcs[idx + 1],
|
||||
(size_t)(g_nsvc - idx - 1) * sizeof(svc_t));
|
||||
(size_t)moved * sizeof(svc_t));
|
||||
/* memmove 整块字节拷贝 svc_t 后,被左移槽位的 argv[] 指针仍指向移动前
|
||||
* (g_svcs[i+1]) 的 exec/argbuf 成员地址 —— 同 *s=tmp 的悬垂,需重定位到
|
||||
* 新槽位自身的成员(svc_rebuild_argv)。否则删除一个服务后,其后被左移的
|
||||
* 槽若在同 tick 内被拉起,execv 会用错位的 argv → cmdline 错乱。 */
|
||||
for (int i = idx; i < idx + moved; i++) svc_rebuild_argv(&g_svcs[i]);
|
||||
}
|
||||
g_nsvc--;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user