(frameID uint64, size int, rng *rand.Rand)
| 36 | } |
| 37 | |
| 38 | func (mod *CANModule) fuzzGenerateFrame(frameID uint64, size int, rng *rand.Rand) (*can.Frame, error) { |
| 39 | dataLen := 0 |
| 40 | frameData := ([]byte)(nil) |
| 41 | |
| 42 | // if we have a DBC |
| 43 | if mod.dbc.Loaded() { |
| 44 | if message := mod.dbc.MessageById(uint32(frameID)); message != nil { |
| 45 | mod.Info("using message %s", message.Name) |
| 46 | dataLen = int(message.Length) |
| 47 | frameData = make([]byte, dataLen) |
| 48 | if _, err := rand.Read(frameData); err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | } else { |
| 52 | return nil, fmt.Errorf("message with id %d not found in DBC file, available ids: %v", frameID, strings.Join(mod.dbc.AvailableMessages(), ", ")) |
| 53 | } |
| 54 | } else { |
| 55 | if size <= 0 { |
| 56 | // pick randomly |
| 57 | dataLen = rng.Intn(int(can.MaxDataLength)) |
| 58 | } else { |
| 59 | // user selected |
| 60 | dataLen = size |
| 61 | } |
| 62 | frameData = make([]byte, dataLen) |
| 63 | if _, err := rand.Read(frameData); err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | mod.Warning("no dbc loaded, creating frame with %d bytes of random data", dataLen) |
| 67 | } |
| 68 | |
| 69 | frame := can.Frame{ |
| 70 | ID: uint32(frameID), |
| 71 | Length: uint8(dataLen), |
| 72 | IsRemote: false, |
| 73 | IsExtended: false, |
| 74 | } |
| 75 | |
| 76 | copy(frame.Data[:], frameData) |
| 77 | |
| 78 | return &frame, nil |
| 79 | } |
| 80 | |
| 81 | func (mod *CANModule) Fuzz(id string, optSize string) error { |
| 82 | rncSource := rand.NewSource(time.Now().Unix()) |
no test coverage detected