Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
cd28a6d9
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cd28a6d9
编写于
1月 14, 2020
作者:
W
Wadeck Follonier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[SECURITY-1641]
上级
c0d3c041
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
2 deletion
+89
-2
core/src/main/java/hudson/DNSMultiCast.java
core/src/main/java/hudson/DNSMultiCast.java
+1
-1
core/src/main/java/hudson/UDPBroadcastThread.java
core/src/main/java/hudson/UDPBroadcastThread.java
+2
-1
test/src/test/java/hudson/UDPBroadcastThreadSEC1641Test.java
test/src/test/java/hudson/UDPBroadcastThreadSEC1641Test.java
+29
-0
test/src/test/java/hudson/UDPBroadcastThreadTest.java
test/src/test/java/hudson/UDPBroadcastThreadTest.java
+57
-0
未找到文件。
core/src/main/java/hudson/DNSMultiCast.java
浏览文件 @
cd28a6d9
...
...
@@ -88,5 +88,5 @@ public class DNSMultiCast implements Closeable {
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
DNSMultiCast
.
class
.
getName
());
public
static
boolean
disabled
=
SystemProperties
.
getBoolean
(
DNSMultiCast
.
class
.
getName
()+
".disabled"
);
public
static
boolean
disabled
=
SystemProperties
.
getBoolean
(
DNSMultiCast
.
class
.
getName
()+
".disabled"
,
true
);
}
core/src/main/java/hudson/UDPBroadcastThread.java
浏览文件 @
cd28a6d9
...
...
@@ -129,7 +129,8 @@ public class UDPBroadcastThread extends Thread {
interrupt
();
}
public
static
final
int
PORT
=
SystemProperties
.
getInteger
(
"hudson.udp"
,
33848
);
// The previous default port was 33848, before the "disabled by default" change
public
static
final
int
PORT
=
SystemProperties
.
getInteger
(
"hudson.udp"
,
-
1
);
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
UDPBroadcastThread
.
class
.
getName
());
...
...
test/src/test/java/hudson/UDPBroadcastThreadSEC1641Test.java
0 → 100644
浏览文件 @
cd28a6d9
package
hudson
;
import
jenkins.model.Jenkins
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
java.lang.reflect.Field
;
import
static
org
.
junit
.
Assert
.
assertNull
;
public
class
UDPBroadcastThreadSEC1641Test
{
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
@Test
public
void
ensureThereIsNoThreadRunningByDefault
()
throws
Exception
{
UDPBroadcastThread
thread
=
getPrivateThread
(
j
.
jenkins
);
assertNull
(
thread
);
}
private
static
UDPBroadcastThread
getPrivateThread
(
Jenkins
jenkins
)
throws
Exception
{
Field
threadField
=
Jenkins
.
class
.
getDeclaredField
(
"udpBroadcastThread"
);
threadField
.
setAccessible
(
true
);
return
(
UDPBroadcastThread
)
threadField
.
get
(
jenkins
);
}
}
test/src/test/java/hudson/UDPBroadcastThreadTest.java
浏览文件 @
cd28a6d9
package
hudson
;
import
jenkins.model.Jenkins
;
import
org.hamcrest.Matchers
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.xml.sax.InputSource
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.helpers.DefaultHandler
;
import
javax.xml.parsers.SAXParserFactory
;
import
javax.xml.parsers.ParserConfigurationException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.net.DatagramSocket
;
import
java.net.DatagramPacket
;
import
java.net.InetAddress
;
...
...
@@ -17,18 +23,40 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
UDPBroadcastThreadTest
{
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
@BeforeClass
public
static
void
forceActivateUDPMulticast
()
throws
Exception
{
// required to be done before JenkinsRule starts the Jenkins instance
// as the usage of this port is in the constructor
updatePort
(
33848
);
}
private
static
void
updatePort
(
int
newValue
)
throws
Exception
{
Field
portField
=
UDPBroadcastThread
.
class
.
getField
(
"PORT"
);
Field
modifiersField
=
Field
.
class
.
getDeclaredField
(
"modifiers"
);
modifiersField
.
setAccessible
(
true
);
modifiersField
.
setInt
(
portField
,
portField
.
getModifiers
()
&
~
Modifier
.
FINAL
);
portField
.
setInt
(
null
,
newValue
);
}
/**
* Old unicast based clients should still be able to receive some reply,
* as we haven't changed the port.
*/
@Test
public
void
legacy
()
throws
Exception
{
updatePort
(
33848
);
DatagramSocket
s
=
new
DatagramSocket
();
sendQueryTo
(
s
,
InetAddress
.
getLocalHost
());
s
.
setSoTimeout
(
15000
);
// to prevent test hang
...
...
@@ -60,18 +88,38 @@ public class UDPBroadcastThreadTest {
// we should at least get two replies since we run two broadcasts
try
{
// from first (Jenkins one) (order does not matter)
receiveAndVerify
(
s
);
// from second
receiveAndVerify
(
s
);
// from third
receiveAndVerify
(
s
);
}
catch
(
SocketTimeoutException
x
)
{
Assume
.
assumeFalse
(
UDPBroadcastThread
.
udpHandlingProblem
);
throw
x
;
}
// to fail fast
s
.
setSoTimeout
(
2000
);
try
{
receiveAndVerify
(
s
);
fail
(
"There should be only 3 listeners"
);
}
catch
(
SocketTimeoutException
x
)
{
// expected to throw
}
}
finally
{
third
.
interrupt
();
second
.
interrupt
();
}
}
@Test
public
void
ensureTheThreadIsRunningWithSysProp
()
throws
Exception
{
UDPBroadcastThread
thread
=
getPrivateThread
(
j
.
jenkins
);
assertNotNull
(
thread
);
assertTrue
(
thread
.
isAlive
());
}
private
void
sendQueryTo
(
DatagramSocket
s
,
InetAddress
dest
)
throws
IOException
{
DatagramPacket
p
=
new
DatagramPacket
(
new
byte
[
1024
],
1024
);
p
.
setAddress
(
dest
);
...
...
@@ -86,11 +134,20 @@ public class UDPBroadcastThreadTest {
DatagramPacket
p
=
new
DatagramPacket
(
new
byte
[
1024
],
1024
);
s
.
receive
(
p
);
String
xml
=
new
String
(
p
.
getData
(),
0
,
p
.
getLength
(),
"UTF-8"
);
//example: <hudson><version>2.164.4-SNAPSHOT</version><url>http://localhost:23146/jenkins/</url><server-id>be6757793486931ff50c259b66c77704</server-id><slave-port>23149</slave-port></hudson>
System
.
out
.
println
(
xml
);
Assert
.
assertThat
(
xml
,
Matchers
.
containsString
(
"<hudson>"
));
// make sure at least this XML parses
SAXParserFactory
spf
=
SAXParserFactory
.
newInstance
();
spf
.
setNamespaceAware
(
true
);
spf
.
newSAXParser
().
parse
(
new
InputSource
(
new
StringReader
(
xml
)),
new
DefaultHandler
());
}
private
static
UDPBroadcastThread
getPrivateThread
(
Jenkins
jenkins
)
throws
Exception
{
Field
threadField
=
Jenkins
.
class
.
getDeclaredField
(
"udpBroadcastThread"
);
threadField
.
setAccessible
(
true
);
return
(
UDPBroadcastThread
)
threadField
.
get
(
jenkins
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录