omaha_request_action_fuzzer.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // Copyright (C) 2018 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include <brillo/message_loops/fake_message_loop.h>
  17. #include "update_engine/common/mock_http_fetcher.h"
  18. #include "update_engine/common/test_utils.h"
  19. #include "update_engine/fake_system_state.h"
  20. #include "update_engine/omaha_request_action.h"
  21. class Environment {
  22. public:
  23. Environment() { logging::SetMinLogLevel(logging::LOG_FATAL); }
  24. };
  25. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  26. static Environment env;
  27. brillo::FakeMessageLoop loop(nullptr);
  28. loop.SetAsCurrent();
  29. chromeos_update_engine::FakeSystemState fake_system_state;
  30. auto omaha_request_action =
  31. std::make_unique<chromeos_update_engine::OmahaRequestAction>(
  32. &fake_system_state,
  33. nullptr,
  34. std::make_unique<chromeos_update_engine::MockHttpFetcher>(
  35. data, size, nullptr),
  36. false);
  37. auto collector_action =
  38. std::make_unique<chromeos_update_engine::ObjectCollectorAction<
  39. chromeos_update_engine::OmahaResponse>>();
  40. BondActions(omaha_request_action.get(), collector_action.get());
  41. chromeos_update_engine::ActionProcessor action_processor;
  42. action_processor.EnqueueAction(std::move(omaha_request_action));
  43. action_processor.EnqueueAction(std::move(collector_action));
  44. action_processor.StartProcessing();
  45. loop.Run();
  46. return 0;
  47. }