-
Notifications
You must be signed in to change notification settings - Fork 144
fix(promote): verify named pipe server process #3042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,13 @@ private static void _PerformAsPromoteProcess(string pid) | |
| var pipeName = _GetPromotePipeName(process.Id); | ||
| var pipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut); | ||
| pipe.Connect(10000); | ||
| var serverProcessId = (int)KernelInterop.GetNamedPipeServerProcessId(pipe.SafePipeHandle.DangerousGetHandle()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the promoted helper reaches this line, Useful? React with 👍 / 👎. |
||
| if (serverProcessId != process.Id) | ||
| { | ||
| Context.Error("管道服务端验证失败,正在退出"); | ||
| pipe.Dispose(); | ||
| return; | ||
| } | ||
| Context.Info("已连接,开始通信"); | ||
| var reader = new StreamReader(pipe); | ||
| var writer = new StreamWriter(pipe); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): 建议不要将服务器 PID 从 uint 强制转换为 int,以避免在较大的 PID 上发生潜在溢出和不匹配。
GetNamedPipeServerProcessId返回uint,而Process.Id是int。当数值超过Int32.MaxValue时,将uint强制转换为int会有溢出风险,并可能得到错误/负数的 PID。相反,建议保持服务器 PID 为uint,并与(uint)process.Id进行比较:Original comment in English
suggestion (bug_risk): Avoid casting the server PID from uint to int to prevent potential overflow and mismatches on large PIDs.
GetNamedPipeServerProcessIdreturns auintwhileProcess.Idis anint. Casting theuinttointrisks overflow and an incorrect/negative PID if values exceedInt32.MaxValue. Instead, keep the server PID asuintand compare against(uint)process.Id: