FSTFuzzTestsPrincipal.mm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2018 Google
  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. #import <Foundation/NSObject.h>
  17. #include "LibFuzzer/FuzzerDefs.h"
  18. #include "Firestore/core/src/firebase/firestore/remote/serializer.h"
  19. using firebase::firestore::remote::Serializer;
  20. namespace {
  21. // Fuzz-test the deserialization process in Firestore. The Serializer reads raw
  22. // bytes and converts them to a model object.
  23. void FuzzTestDeserialization(const uint8_t *data, size_t size) {
  24. // TODO(minafarid): fuzz-test Serializer.
  25. }
  26. // Contains the code to be fuzzed. Called by the fuzzing library with
  27. // different argument values for `data` and `size`.
  28. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  29. FuzzTestDeserialization(data, size);
  30. return 0;
  31. }
  32. // Simulates calling the main() function of libFuzzer (FuzzerMain.cpp).
  33. int RunFuzzTestingMain() {
  34. // Arguments to libFuzzer main() function should be added to this array,
  35. // e.g., dictionaries, corpus, number of runs, jobs, etc.
  36. char *program_args[] = {
  37. const_cast<char *>("RunFuzzTestingMain") // First arg is program name.
  38. };
  39. char **argv = program_args;
  40. int argc = sizeof(program_args) / sizeof(program_args[0]);
  41. // Start fuzzing using libFuzzer's driver.
  42. return fuzzer::FuzzerDriver(&argc, &argv, LLVMFuzzerTestOneInput);
  43. }
  44. } // namespace
  45. /**
  46. * This class is registered as the NSPrincipalClass in the
  47. * Firestore_FuzzTests_iOS bundle's Info.plist. XCTest instantiates this class
  48. * to perform one-time setup for the test bundle, as documented here:
  49. *
  50. * https://developer.apple.com/documentation/xctest/xctestobservationcenter
  51. */
  52. @interface FSTFuzzTestsPrincipal : NSObject
  53. @end
  54. @implementation FSTFuzzTestsPrincipal
  55. - (instancetype)init {
  56. self = [super init];
  57. RunFuzzTestingMain();
  58. return self;
  59. }
  60. @end