Skip to content

Commit

Permalink
[inih] Fix Issue 68332 (#11836)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkillarjun authored May 2, 2024
1 parent d82c8c1 commit 28760cf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
5 changes: 3 additions & 2 deletions projects/inih/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update
RUN git clone https://github.com/benhoyt/inih
COPY build.sh $SRC/
RUN git clone https://github.com/benhoyt/inih.git
COPY inihfuzz.c $SRC/inih/inihfuzz.c
COPY build.sh $SRC/build.sh
WORKDIR $SRC/inih/
13 changes: 8 additions & 5 deletions projects/inih/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -eu
# Copyright 2023 Google LLC
# 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.
Expand All @@ -14,10 +14,13 @@
# limitations under the License.
#
################################################################################
pushd fuzzing/
bash oss-fuzz.sh
cp inihfuzz $OUT/
popd

# Compile the fuzzer binary for oss-fuzz infrastructure.
$CC $CFLAGS -c ini.c
$CC $CFLAGS -c inihfuzz.c
$CXX $CFLAGS $LIB_FUZZING_ENGINE inihfuzz.o ini.o -o inihfuzz

# Setup for oss-fuzz infrastructure.
cp inihfuzz $OUT/
zip -r inihfuzz_seed_corpus.zip tests/*.ini
mv inihfuzz_seed_corpus.zip $OUT/
59 changes: 59 additions & 0 deletions projects/inih/inihfuzz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ini.h"

#define kMinInputLength 8
#define kMaxInputLength 512

int User;
char Prev_section[50];

int dumper(void* user, const char* section, const char* name,
const char* value)
{
User = *((int*)user);
if (strcmp(section, Prev_section)) {
strncpy(Prev_section, section, sizeof(Prev_section));
Prev_section[sizeof(Prev_section) - 1] = '\0';
}
return 1;
}

extern int LLVMFuzzerTestOneInput(const char *data, size_t size) {
if (size < kMinInputLength || size > kMaxInputLength) {
return 0;
}

int e;
static int u = 100;
Prev_section[0] = '\0';

char *data_in = malloc(size + 1);
if (!data_in) return 0; // Just in case malloc fails

memcpy(data_in, data, size);
data_in[size] = '\0';

e = ini_parse_string(data_in, dumper, &u);

free(data_in);

return e;
}
2 changes: 1 addition & 1 deletion projects/inih/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ homepage: "https://github.com/benhoyt/inih"
language: c
primary_contact: "[email protected]"
auto_ccs:
- "ajsinghyadav00@gmail.com"
- "pkillarjun@protonmail.com"
fuzzing_engines:
- libfuzzer
- afl
Expand Down

0 comments on commit 28760cf

Please sign in to comment.