summaryrefslogtreecommitdiff
path: root/chromium/components/password_manager/core/browser/form_parsing/fuzzer/form_parser_proto_generic_fuzzer.cc
blob: b02e04b16ea459ba317701069c08b523f377ec57 (plain)
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>
#include <stdint.h>

#include <memory>

#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/form_parsing/form_parser.h"
#include "components/password_manager/core/browser/form_parsing/fuzzer/form_data_essentials.pb.h"
#include "components/password_manager/core/browser/form_parsing/fuzzer/form_data_proto_producer.h"
#include "testing/libfuzzer/proto/lpm_interface.h"

namespace password_manager {

// ICU is used inside GURL parser, which is used by GenerateWithDataAccessor.
struct IcuEnvironment {
  IcuEnvironment() { CHECK(base::i18n::InitializeICU()); }
  // used by ICU integration.
  base::AtExitManager at_exit_manager;
};

IcuEnvironment* env = new IcuEnvironment();

DEFINE_BINARY_PROTO_FUZZER(const ::form_data_fuzzer::Form& form_proto) {
  FormParsingMode mode = form_proto.is_mode_filling() ? FormParsingMode::FILLING
                                                      : FormParsingMode::SAVING;
  autofill::FormData form_data = GenerateWithProto(form_proto);

  std::unique_ptr<autofill::PasswordForm> result =
      ParseFormData(form_data, nullptr, mode);
  if (result) {
    // Create a copy of the result -- running the copy-constructor might
    // discover some invalid data in |result|.
    autofill::PasswordForm copy(*result);
  }
}

}  // namespace password_manager