Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钱炳权
fuzzBackEnd
Commits
b7729b83
Commit
b7729b83
authored
8 months ago
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常定位开发完成
parent
99d14daf
qbq-dev
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
161 additions
and
19 deletions
+161
-19
AflnetDataController.java
...troll/controller/dataController/AflnetDataController.java
+21
-6
TestService.java
...in/java/com/example/fuzzControll/service/TestService.java
+3
-1
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+48
-3
SystemRunningParams.java
...xample/fuzzControll/tools/system/SystemRunningParams.java
+5
-1
TestCmdTools.java
...ava/com/example/fuzzControll/tools/test/TestCmdTools.java
+60
-2
TestController.java
.../example/fuzzbackendmaster/controller/TestController.java
+15
-4
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+9
-2
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/dataController/AflnetDataController.java
View file @
b7729b83
...
...
@@ -4,6 +4,7 @@ import com.example.fuzzControll.domain.bo.AflnetDataParams;
import
com.example.fuzzControll.domain.vo.AjaxResult
;
import
com.example.fuzzControll.service.AflnetPersistenceService
;
import
com.example.fuzzControll.service.TestService
;
import
com.example.fuzzControll.tools.system.SystemRunningParams
;
import
com.example.fuzzControll.tools.test.TestCmdTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -35,25 +36,39 @@ public class AflnetDataController {
}
return
AjaxResult
.
success
(
"File loaded successfully!"
);
}
/**
* 异常重放
(查看堆栈)
* 异常重放
*/
@RequestMapping
(
value
=
"/replay"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
replay
(
@RequestParam
String
programPath
)
{
public
AjaxResult
replay
(
@RequestParam
String
targetServer
,
@RequestParam
String
targetServerCodePath
,
@RequestParam
String
targetServerPort
,
@RequestParam
String
protocol
,
@RequestParam
String
pathToCrash
)
{
try
{
testService
.
replay
(
targetServer
,
targetServerCodePath
,
targetServerPort
,
protocol
,
pathToCrash
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"Replay failed!"
);
}
return
AjaxResult
.
success
(
"Replay successfully!"
);
}
/**
* 异常分析
*/
@RequestMapping
(
value
=
"/analyse"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
analyse
(
@RequestParam
String
codePath
,
@RequestParam
String
programName
)
{
try
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
testService
.
replay
(
programPath
);
testService
.
analyse
(
codePath
,
programName
);
}
}).
start
();
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
AjaxResult
.
error
(
"
Replay
failed!"
);
return
AjaxResult
.
error
(
"
Analyse
failed!"
);
}
return
AjaxResult
.
success
(
"
Start replay
success!"
);
return
AjaxResult
.
success
(
"
Analyse
success!"
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/TestService.java
View file @
b7729b83
...
...
@@ -14,7 +14,9 @@ public interface TestService {
LinkedHashMap
<
String
,
String
>
getProcessInfo
();
void
replay
(
String
programPath
);
void
analyse
(
String
codePath
,
String
programPath
);
List
<
String
>
getReplayResult
();
void
replay
(
String
targetServer
,
String
targetServerCodePath
,
String
targetServerPort
,
String
protocol
,
String
pathToCrash
);
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
b7729b83
...
...
@@ -20,6 +20,7 @@ import com.example.fuzzControll.tools.system.SystemRunningParams;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
...
...
@@ -28,6 +29,7 @@ import java.util.Date;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
@Service
(
"testService"
)
@Slf4j
...
...
@@ -92,9 +94,8 @@ public class TestServiceImpl implements TestService {
}
@Override
public
void
replay
(
String
programPath
)
{
String
cmd
=
"gdb /usr/fuzzenv/fuzzenv/live555/testProgs/"
+
programPath
+
" /usr/fuzzenv/fuzzenv/live555/testProgs/core"
+
" > /usr/dump.txt"
;
public
void
analyse
(
String
codePath
,
String
programPath
)
{
String
cmd
=
"gdb "
+
codePath
+
programPath
+
" "
+
codePath
+
"core"
;
log
.
info
(
"Replay cmd is {}"
,
cmd
);
SystemRunningParams
.
ReplayResults
=
new
ArrayList
<>();
try
{
...
...
@@ -108,6 +109,7 @@ public class TestServiceImpl implements TestService {
@Override
public
List
<
String
>
getReplayResult
()
{
/*停止GDB*/
SystemRunningParams
.
ReplayResults
=
new
ArrayList
<>();
try
{
cmdTools
.
runCmd
(
"pkill gdb"
,
"getReplayResult-stopGdb"
);
}
catch
(
CmdException
e
)
{
...
...
@@ -131,4 +133,47 @@ public class TestServiceImpl implements TestService {
// }
return
SystemRunningParams
.
ReplayResults
;
}
@Override
public
void
replay
(
String
targetServer
,
String
targetServerCodePath
,
String
targetServerPort
,
String
protocol
,
String
pathToCrash
)
{
/*删除当前目录生成的dump文件*/
try
{
List
<
String
>
temp
=
new
ArrayList
<
String
>();
int
m
=
0
;
while
(
m
<=
1
)
{
temp
=
cmdTools
.
runCmdReturnError
(
CmdConstent
.
DELETE_FILE
+
targetServerCodePath
+
"core"
,
"replay-removeFile"
);
m
++;
}
if
(
temp
.
stream
().
noneMatch
(
s
->
s
.
contains
(
"No such file or directory"
)))
{
throw
new
RuntimeException
(
"Remove failed!"
);
}
}
catch
(
RuntimeException
e
)
{
log
.
error
(
"File remove failed:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
/*启动目标服务器,存在阻塞所以新开另外起线程*/
SystemRunningParams
.
ReplayRunServerMessage
=
new
ArrayList
<>();
int
i
=
0
;
while
(
i
<=
1
)
{
//两次保证服务器可以启动
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
String
runServerCmd
=
targetServerCodePath
+
targetServer
+
" "
+
targetServerPort
;
log
.
info
(
"Server start cmd is:[{}]"
,
runServerCmd
);
TestCmdTools
cmdTools
=
new
TestCmdTools
();
cmdTools
.
runClogCmd
(
runServerCmd
,
SystemRunningParams
.
ReplayRunServerMessage
,
"replay-startServer"
);
}
}).
start
();
i
++;
}
/*异常重放,会自动引起服务器关闭*/
try
{
//保证服务器成功启动
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
String
crashCmd
=
"aflnet-replay"
+
" "
+
pathToCrash
+
" "
+
protocol
+
" "
+
targetServerPort
;
log
.
info
(
"Replay crash cmd is:[{}]"
,
crashCmd
);
cmdTools
.
runCmd
(
crashCmd
,
"replay-crash"
);
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/system/SystemRunningParams.java
View file @
b7729b83
...
...
@@ -41,9 +41,13 @@ public class SystemRunningParams {
public
static
LinkedHashMap
<
String
,
String
>
TestProgressMap
=
new
LinkedHashMap
<>();
/**
* 异常重放数据
* 异常重放
结果
数据
*/
public
static
List
<
String
>
ReplayResults
=
new
ArrayList
<>();
/**
* 异常重放启动服务器信息数据
*/
public
static
List
<
String
>
ReplayRunServerMessage
=
new
ArrayList
<>();
public
static
void
init
()
{
/*初始化aflnet和kitty时间参数*/
testTimeMessage
.
put
(
"aflnet"
,
new
ConcurrentHashMap
<>());
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/test/TestCmdTools.java
View file @
b7729b83
...
...
@@ -29,6 +29,64 @@ public class TestCmdTools {
Boolean
send
=
false
;
Boolean
show
=
true
;
/**
* 运行指令返回错误信息
*/
public
List
<
String
>
runCmdReturnError
(
String
cmd
,
String
caller
)
throws
CmdException
{
List
<
String
>
result
=
new
ArrayList
<
String
>();
List
<
String
>
error
=
new
ArrayList
<
String
>();
try
{
log
.
info
(
caller
+
" is running!"
);
log
.
info
(
"Running cmd:[{}]"
,
cmd
);
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessage
(
process
.
getInputStream
(),
result
);
printMessage
(
process
.
getErrorStream
(),
error
);
process
.
waitFor
();
log
.
info
(
caller
+
" end!"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
CmdException
(
caller
+
" run cmd failed!"
);
}
return
error
;
}
/**
* 运行会阻塞的命令行
*/
public
List
<
String
>
runClogCmd
(
String
cmd
,
List
<
String
>
response
,
String
caller
)
throws
CmdException
{
try
{
log
.
info
(
caller
+
" is running!"
);
log
.
info
(
"Running cmd:[{}]"
,
cmd
);
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
printMessageClogCmd
(
process
.
getInputStream
(),
response
);
printMessageClogCmd
(
process
.
getErrorStream
(),
new
ArrayList
<>());
process
.
waitFor
();
log
.
info
(
caller
+
" end!"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
CmdException
(
caller
+
" run cmd failed!"
);
}
return
response
;
}
private
void
printMessageClogCmd
(
InputStream
inputStream
,
List
<
String
>
response
)
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Reader
reader
=
new
InputStreamReader
(
inputStream
);
BufferedReader
bf
=
new
BufferedReader
(
reader
);
String
line
=
null
;
try
{
while
((
line
=
bf
.
readLine
())
!=
null
)
{
log
.
info
(
line
);
response
.
add
(
line
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}).
start
();
}
/**
* 运行不需要后台运行cmd
...
...
@@ -48,7 +106,6 @@ public class TestCmdTools {
e
.
printStackTrace
();
throw
new
CmdException
(
caller
+
" run cmd failed!"
);
}
return
result
;
}
//todo 不同协议种子路径也不同
...
...
@@ -76,7 +133,8 @@ public class TestCmdTools {
* 运行需要后台运行cmd
* 将数据存入文件中
*/
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
,
String
caller
,
String
missionName
)
throws
CmdException
{
public
Map
<
String
,
List
<
String
>>
runProgramCmdAndResult
(
String
cmd
,
String
caller
,
String
missionName
)
throws
CmdException
{
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
();
List
<
String
>
out
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
List
<
String
>
error
=
Collections
.
synchronizedList
(
new
ArrayList
<
String
>());
...
...
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/TestController.java
View file @
b7729b83
...
...
@@ -48,11 +48,21 @@ public class TestController {
}
/**
* 异常重放
分析
* 异常重放
*/
@RequestMapping
(
value
=
"/replay"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
replay
(
@RequestParam
String
programPath
)
{
return
fuzzIntegrationFileApi
.
replay
(
programPath
);
public
AjaxResult
replay
(
@RequestParam
String
targetServer
,
@RequestParam
String
targetServerCodePath
,
@RequestParam
String
targetServerPort
,
@RequestParam
String
protocol
,
@RequestParam
String
pathToCrash
)
{
return
fuzzIntegrationFileApi
.
replay
(
targetServer
,
targetServerCodePath
,
targetServerPort
,
protocol
,
pathToCrash
);
}
/**
* 异常重放分析
*/
@RequestMapping
(
value
=
"/analyse"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
analyse
(
@RequestParam
String
codePath
,
@RequestParam
String
programName
)
{
return
fuzzIntegrationFileApi
.
analyse
(
codePath
,
programName
);
}
/**
...
...
@@ -60,6 +70,6 @@ public class TestController {
*/
@RequestMapping
(
value
=
"/getreplayresult"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getReplayResult
()
{
return
fuzzIntegrationFileApi
.
getReplayResult
(
);
return
fuzzIntegrationFileApi
.
getReplayResult
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
b7729b83
...
...
@@ -136,12 +136,19 @@ public interface FuzzIntegrationFileApi {
/**
* 异常重放分析
*/
@RequestMapping
(
value
=
"/aflnet/
replay
"
,
method
=
RequestMethod
.
GET
)
AjaxResult
replay
(
@RequestParam
String
programPath
);
@RequestMapping
(
value
=
"/aflnet/
analyse
"
,
method
=
RequestMethod
.
GET
)
AjaxResult
analyse
(
@RequestParam
String
codePath
,
@RequestParam
String
programName
);
/**
* 获取异常分析结果
*/
@RequestMapping
(
value
=
"/aflnet/getreplayresult"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getReplayResult
();
/**
* 异常重放
*/
@RequestMapping
(
value
=
"/aflnet/replay"
,
method
=
RequestMethod
.
GET
)
AjaxResult
replay
(
@RequestParam
String
targetServer
,
@RequestParam
String
targetServerCodePath
,
@RequestParam
String
targetServerPort
,
@RequestParam
String
protocol
,
@RequestParam
String
pathToCrash
);
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment