Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b718d671 authored by Zach Johnson's avatar Zach Johnson
Browse files

Add gd/fuzzing/helpers

A comon place for common helpers across fuzz tests for GD.

Test: new fuzz test I'm working on
Change-Id: I9897edd3822173e78a6f1028c2c3ff58fac61732
parent 955d9f66
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
filegroup {
    name: "BluetoothFuzzingHelperSources",
    srcs: [
        "helpers.cc",
    ],
}
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "fuzzing/helpers.h"

namespace bluetooth {
namespace fuzzing {

// cribbed from https://github.com/google/fuzzing/blob/master/docs/split-inputs.md#magic-separator
std::vector<std::vector<uint8_t>> SplitInput(const uint8_t* data, size_t size, const uint8_t* separator,
                                             size_t separatorSize) {
  std::vector<std::vector<uint8_t>> result;
  assert(SeparatorSize > 0);
  auto beg = data;
  auto end = data + size;
  while (const uint8_t* pos = (const uint8_t*)memmem(beg, end - beg, separator, separatorSize)) {
    result.push_back({beg, pos});
    beg = pos + separatorSize;
  }
  if (beg < end) {
    result.push_back({beg, end});
  }
  return result;
}

}  // namespace fuzzing
}  // namespace bluetooth
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cstdint>
#include <vector>

namespace bluetooth {
namespace fuzzing {

std::vector<std::vector<uint8_t>> SplitInput(const uint8_t* data, size_t size, const uint8_t* separator,
                                             size_t separatorSize);

}
}  // namespace bluetooth