Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modp_b64: project initialisation #12644

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions projects/modp_b64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Google LLC
#
# 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.
#
################################################################################

FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && \
apt-get install -y \
build-essential \
autoconf \
automake \
libtool \
pkg-config

RUN git clone https://github.com/Piasy/modp_b64 modp_b64
WORKDIR $SRC/modp_b64

COPY *_fuzzer.cc build.sh $SRC/
30 changes: 30 additions & 0 deletions projects/modp_b64/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -eu
#
# Copyright 2024 Google LLC
#
# 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.
#
################################################################################

# Build the source files
$CXX $CXXFLAGS -I$SRC/modp_b64/modp_b64 -c modp_b64.cc -o $OUT/modp_b64.a

# Build existing fuzzers
for fuzzers in $(find $SRC -name '*_fuzzer.cc'); do
fuzz_basename=$(basename -s .cc $fuzzers)
$CC $CXXFLAGS -I$SRC/modp_b64/modp_b64 \
-I$SRC/modp_b64 -c $fuzzers -o $fuzz_basename.o

$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzz_basename.o \
-o $OUT/$fuzz_basename $OUT/modp_b64.a
done
58 changes: 58 additions & 0 deletions projects/modp_b64/modp_b64_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 Google LLC
//
// 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 <string>
#include <cstddef>
#include <cstdint>
#include "modp_b64.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Skip this iteration if not enough data
if (size < 2) {
return 0;
}

// Initialise buffer, input and choice
int choice = data[0] % 3;
std::string buffer;
buffer.resize(modp_b64_encode_len(size));
std::string input(reinterpret_cast<const char*>(data), size);

// Randomly fuzz encode, decode or round trip functions
switch (choice) {
case 0: {
modp_b64_encode(&buffer[0], input.c_str(), size);
break;
}
case 1: {
buffer.resize(modp_b64_decode_len(size));
modp_b64_decode(&buffer[0], input.c_str(), size);
break;
}
case 2: {
modp_b64_encode(input);
modp_b64_decode(input);
break;
}
default:
break;
}

// Clean up memory
buffer.clear();
input.clear();

return 0;
}

6 changes: 6 additions & 0 deletions projects/modp_b64/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
homepage: "https://github.com/Piasy/modp_b64"
main_repo: "https://github.com/Piasy/modp_b64"
language: c++
vendor_ccs:
- "[email protected]"
- "[email protected]"