--- /dev/null
+/*
+ Fuzzing for trivial smb.conf parsing code.
+ Copyright (C) Michael Hanselmann 2019
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "fuzzing.h"
+#include "lib/util/tiniparser.h"
+
+int LLVMFuzzerInitialize(int *argc, char ***argv)
+{
+ return 0;
+}
+
+int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
+{
+ FILE *fp;
+
+ fp = fmemopen(buf, len, "r");
+
+ tiniparser_load_stream(fp);
+
+ fclose(fp);
+
+ return 0;
+}
deps='talloc',
enabled=bld.env.enable_libfuzzer,
)
+
+bld.SAMBA_BINARY('fuzz_tiniparser',
+ source='fuzz_tiniparser.c',
+ deps='fuzzing tiniparser talloc',
+ install=False,
+ enabled=bld.env.enable_libfuzzer)
return true;
}
-struct tiniparser_dictionary *tiniparser_load(const char *filename)
+struct tiniparser_dictionary *tiniparser_load_stream(FILE *fp)
{
bool ret;
struct tiniparser_dictionary *d = NULL;
- FILE *fp = fopen(filename, "r");
-
- if (fp == NULL) {
- return NULL;
- }
d = malloc(sizeof(struct tiniparser_dictionary));
if (d == NULL) {
section_parser,
value_parser,
d);
- fclose(fp);
if (ret == false) {
tiniparser_freedict(d);
d = NULL;
return d;
}
+struct tiniparser_dictionary *tiniparser_load(const char *filename)
+{
+ struct tiniparser_dictionary *d;
+ FILE *fp = fopen(filename, "r");
+
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ d = tiniparser_load_stream(fp);
+
+ fclose(fp);
+
+ return d;
+}
+
void tiniparser_freedict(struct tiniparser_dictionary *d)
{
struct tiniparser_section *curr_section, *next_section;
int tiniparser_getint(struct tiniparser_dictionary *d,
const char *key,
int default_value);
+struct tiniparser_dictionary *tiniparser_load_stream(FILE *fp);
struct tiniparser_dictionary *tiniparser_load(const char *filename);
void tiniparser_freedict(struct tiniparser_dictionary *d);