fido_ble_frames_fuzzer.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <vector>
  7. #include "device/fido/cable/fido_ble_frames.h"
  8. #include "device/fido/fido_constants.h"
  9. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* raw_data, size_t size) {
  10. auto data_span = base::make_span(raw_data, size);
  11. std::vector<uint8_t> data(data_span.begin(), data_span.end());
  12. {
  13. device::FidoBleFrameInitializationFragment fragment(
  14. device::FidoBleDeviceCommand::kMsg, 21123, data_span);
  15. std::vector<uint8_t> buffer;
  16. fragment.Serialize(&buffer);
  17. device::FidoBleFrameInitializationFragment parsed_fragment;
  18. device::FidoBleFrameInitializationFragment::Parse(data, &parsed_fragment);
  19. device::FidoBleFrameInitializationFragment::Parse(buffer, &parsed_fragment);
  20. buffer.clear();
  21. parsed_fragment.Serialize(&buffer);
  22. }
  23. {
  24. device::FidoBleFrameContinuationFragment fragment(data_span, 61);
  25. std::vector<uint8_t> buffer;
  26. fragment.Serialize(&buffer);
  27. device::FidoBleFrameContinuationFragment parsed_fragment;
  28. device::FidoBleFrameContinuationFragment::Parse(data, &parsed_fragment);
  29. device::FidoBleFrameContinuationFragment::Parse(buffer, &parsed_fragment);
  30. buffer.clear();
  31. parsed_fragment.Serialize(&buffer);
  32. }
  33. {
  34. device::FidoBleFrame frame(device::FidoBleDeviceCommand::kPing, data);
  35. auto fragments = frame.ToFragments(20);
  36. device::FidoBleFrameAssembler assembler(fragments.first);
  37. while (!fragments.second.empty()) {
  38. assembler.AddFragment(fragments.second.front());
  39. fragments.second.pop();
  40. }
  41. auto result_frame = std::move(*assembler.GetFrame());
  42. result_frame.command();
  43. }
  44. return 0;
  45. }