This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathfuzze2e.go
73 lines (66 loc) · 1.63 KB
/
fuzze2e.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package fuzze2e
import (
"flag"
"log"
"net"
"github.com/grailbio/go-dicom"
"github.com/grailbio/go-netdicom"
"github.com/grailbio/go-netdicom/dimse"
"github.com/grailbio/go-netdicom/sopclass"
)
func startServer(faults netdicom.FaultInjector) net.Listener {
netdicom.SetProviderFaultInjector(faults)
listener, err := net.Listen("tcp", ":0")
if err != nil {
log.Panic(err)
}
go func() {
// TODO(saito) test w/ small PDU.
params := netdicom.ServiceProviderParams{
CStore: func(
connState netdicom.ConnectionState,
transferSyntaxUID string,
sopClassUID string,
sopInstanceUID string,
data []byte) dimse.Status {
return dimse.Status{Status: dimse.StatusSuccess}
},
}
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("Accept error: %v", err)
break
}
log.Printf("Accepted connection %v", conn)
netdicom.RunProviderForConn(conn, params)
}
}()
return listener
}
func runClient(serverAddr string, faults netdicom.FaultInjector) {
dataset, err := dicom.ReadDataSetFromFile(
"../testdata/reportsi.dcm",
dicom.ReadOptions{})
if err != nil {
log.Fatal(err)
}
netdicom.SetUserFaultInjector(faults)
su, err := netdicom.NewServiceUser(netdicom.ServiceUserParams{SOPClasses: sopclass.StorageClasses})
if err != nil {
log.Fatal(err)
}
su.Connect(serverAddr)
err = su.CStore(dataset)
log.Printf("Store done with status: %v", err)
su.Release()
}
func init() {
flag.Parse()
}
func Fuzz(data []byte) int {
listener := startServer(netdicom.NewFuzzFaultInjector(data))
runClient(listener.Addr().String(), netdicom.NewFuzzFaultInjector(data))
listener.Close()
return 0
}