Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d71378a7
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d71378a7
编写于
4月 23, 2015
作者:
J
Jared Parsons
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2213 from jaredpar/fix-pipe
Change named pipe ownership check
上级
8f0df9c7
324458c8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
15 deletion
+64
-15
src/Compilers/Core/MSBuildTask/BuildClient.cs
src/Compilers/Core/MSBuildTask/BuildClient.cs
+64
-15
未找到文件。
src/Compilers/Core/MSBuildTask/BuildClient.cs
浏览文件 @
d71378a7
...
...
@@ -29,7 +29,7 @@ internal static class BuildClient
// Spend up to 1s connecting to existing process (existing processes should be always responsive).
private
const
int
TimeOutMsExistingProcess
=
1000
;
// Spend up to 20s connecting to a new process, to allow time for it to start.
private
const
int
TimeOutMsNewProcess
=
20000
;
private
const
int
TimeOutMsNewProcess
=
20000
;
/// <summary>
/// Run a compilation through the compiler server and print the output
...
...
@@ -109,7 +109,7 @@ private static int HandleResponse(BuildResponse response)
/// </summary>
public
static
Task
<
BuildResponse
>
TryRunServerCompilation
(
RequestLanguage
language
,
string
clientDir
,
string
clientDir
,
string
workingDir
,
IList
<
string
>
arguments
,
CancellationToken
cancellationToken
,
...
...
@@ -332,10 +332,7 @@ private static int HandleResponse(BuildResponse response)
cancellationToken
.
ThrowIfCancellationRequested
();
// Verify that we own the pipe.
SecurityIdentifier
currentIdentity
=
WindowsIdentity
.
GetCurrent
().
Owner
;
PipeSecurity
remoteSecurity
=
pipeStream
.
GetAccessControl
();
IdentityReference
remoteOwner
=
remoteSecurity
.
GetOwner
(
typeof
(
SecurityIdentifier
));
if
(
remoteOwner
!=
currentIdentity
)
if
(!
CheckPipeConnectionOwnership
(
pipeStream
))
{
Log
(
"Owner of named pipe is incorrect"
);
return
null
;
...
...
@@ -381,15 +378,15 @@ private static bool TryCreateServerProcess(string clientDir, string pipeName)
var
builder
=
new
StringBuilder
(
$@"""
{
expectedPath
}
"" ""-pipename:
{
pipeName
}
"""
);
bool
success
=
CreateProcess
(
lpApplicationName
:
null
,
lpCommandLine
:
builder
,
lpProcessAttributes
:
NullPtr
,
lpThreadAttributes
:
NullPtr
,
bInheritHandles
:
false
,
dwCreationFlags
:
dwCreationFlags
,
lpEnvironment
:
NullPtr
,
// Inherit environment
lpCurrentDirectory
:
clientDir
,
lpStartupInfo
:
ref
startInfo
,
lpApplicationName
:
null
,
lpCommandLine
:
builder
,
lpProcessAttributes
:
NullPtr
,
lpThreadAttributes
:
NullPtr
,
bInheritHandles
:
false
,
dwCreationFlags
:
dwCreationFlags
,
lpEnvironment
:
NullPtr
,
// Inherit environment
lpCurrentDirectory
:
clientDir
,
lpStartupInfo
:
ref
startInfo
,
lpProcessInformation
:
out
processInfo
);
if
(
success
)
...
...
@@ -404,5 +401,57 @@ private static bool TryCreateServerProcess(string clientDir, string pipeName)
}
return
success
;
}
/// <summary>
/// Check to ensure that the named pipe server we connected to is owned by the same
/// user.
/// </summary>
/// <remarks>
/// The type is embedded in assemblies that need to run cross platform. While this particular
/// code will never be hit when running on non-Windows platforms it does need to work when
/// on Windows. To facilitate that we use reflection to make the check here to enable it to
/// compile into our cross plat assemblies.
/// </remarks>
private
static
bool
CheckPipeConnectionOwnership
(
NamedPipeClientStream
pipeStream
)
{
try
{
var
assembly
=
typeof
(
object
).
Assembly
;
var
currentIdentity
=
assembly
.
GetType
(
"System.Security.Principal.WindowsIdentity"
)
.
GetTypeInfo
()
.
GetDeclaredMethods
(
"GetCurrent"
)
.
Single
(
x
=>
x
.
GetParameters
().
Length
==
0
)
.
Invoke
(
null
,
null
);
var
currentOwner
=
assembly
.
GetType
(
"System.Security.Principal.WindowsIdentity"
)
.
GetTypeInfo
()
.
GetDeclaredProperty
(
"Owner"
)
.
GetGetMethod
()
.
Invoke
(
currentIdentity
,
null
);
var
remotePipeSecurity
=
typeof
(
PipeStream
)
.
GetTypeInfo
()
.
GetDeclaredMethods
(
"GetAccessControl"
)
.
Single
(
x
=>
x
.
GetParameters
().
Length
==
0
)
.
Invoke
(
pipeStream
,
null
);
var
remoteOwner
=
assembly
.
GetType
(
"System.Security.AccessControl.ObjectSecurity"
)
.
GetTypeInfo
()
.
GetDeclaredMethods
(
"GetOwner"
)
.
Single
(
x
=>
x
.
GetParameters
().
Length
==
1
&&
x
.
GetParameters
()[
0
].
ParameterType
==
typeof
(
Type
))
.
Invoke
(
remotePipeSecurity
,
new
[]
{
assembly
.
GetType
(
"System.Security.Principal.SecurityIdentifier"
)
});
return
currentOwner
.
Equals
(
remoteOwner
);
}
catch
(
Exception
ex
)
{
Log
(
"Exception checking pipe connection: {0}"
,
ex
.
Message
);
return
false
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录