1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-24 06:50:08 +03:00

fuzz: Remove hacks to build lint fuzzer

Don't include source file directly.
This commit is contained in:
Nick Wellnhofer 2025-01-17 17:09:04 +01:00
parent bf1d8b9cfb
commit bfe6af2eed
12 changed files with 61 additions and 27 deletions

View File

@ -461,7 +461,7 @@ if(MSVC AND BUILD_SHARED_LIBS)
endif()
if(LIBXML2_WITH_PROGRAMS)
add_executable(xmllint xmllint.c shell.c)
add_executable(xmllint xmllint.c shell.c lintmain.c)
set(PROGRAMS xmllint)
if(LIBXML2_WITH_CATALOG AND LIBXML2_WITH_OUTPUT)
add_executable(xmlcatalog xmlcatalog.c)

View File

@ -139,7 +139,7 @@ runsuite_SOURCES=runsuite.c
runsuite_DEPENDENCIES = $(DEPS)
runsuite_LDADD= $(LDADDS)
xmllint_SOURCES = xmllint.c shell.c
xmllint_SOURCES = xmllint.c shell.c lintmain.c
xmllint_CFLAGS = $(AM_CFLAGS) $(RDL_CFLAGS) $(ICONV_CFLAGS)
xmllint_DEPENDENCIES = $(DEPS)
xmllint_LDADD= $(RDL_LIBS) $(LDADDS)

View File

@ -41,7 +41,7 @@ AC_SUBST(LIBXML_VERSION_INFO)
AC_SUBST(LIBXML_VERSION_NUMBER)
AC_SUBST(LIBXML_VERSION_EXTRA)
AM_INIT_AUTOMAKE([1.16.3 foreign no-dist-gzip dist-xz])
AM_INIT_AUTOMAKE([1.16.3 foreign subdir-objects no-dist-gzip dist-xz])
AM_MAINTAINER_MODE([enable])
AM_SILENT_RULES([yes])

View File

@ -143,7 +143,7 @@ seed/lint.stamp: genSeed$(EXEEXT)
./genSeed$(EXEEXT) lint $(XML_SEED_CORPUS_SRC)
@touch seed/lint.stamp
lint_SOURCES = lint.c fuzz.c
lint_SOURCES = lint.c fuzz.c ../xmllint.c ../shell.c
lint_LDFLAGS = -fsanitize=fuzzer
fuzz-lint: lint$(EXEEXT) seed/lint.stamp

View File

@ -14,10 +14,31 @@
#include <libxml/xmlerror.h>
#include <libxml/xmlmemory.h>
#include "private/lint.h"
#include "fuzz.h"
#define XMLLINT_FUZZ
#include "../xmllint.c"
/*
* Untested options:
*
* --catalogs: Requires XML catalogs
*
* --dtdvalid:
* --dtdvalidfpi: Requires an external DTD
*
* --output: Writes to disk
*
* --path: Requires cooperation with resource loader
*
* --repeat: Could be limited to 2 when fuzzing
*
* --relaxng:
* --schema:
* --schematron: Requires schemas
*
* --shell: We could pipe fuzz data to stdin but this is probably
* not worth it.
*/
static const char *const switches[] = {
"--auto",

View File

@ -8,11 +8,11 @@ EXTRA_DIST = \
globals.h \
html.h \
io.h \
lint.h \
memory.h \
parser.h \
regexp.h \
save.h \
shell.h \
string.h \
threads.h \
tree.h \

15
include/private/lint.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef XML_LINT_H_PRIVATE__
#define XML_LINT_H_PRIVATE__
#include <stdio.h>
#include <libxml/parser.h>
int
xmllintMain(int argc, const char **argv, FILE *errStream,
xmlResourceLoader loader);
void
xmllintShell(xmlDocPtr doc, const char *filename, FILE *output);
#endif /* XML_LINT_H_PRIVATE__ */

View File

@ -1,7 +0,0 @@
#ifndef XML_SHELL_H_PRIVATE__
#define XML_SHELL_H_PRIVATE__
void
xmllintShell(xmlDocPtr doc, const char *filename, FILE *output);
#endif /* XML_SHELL_H_PRIVATE__ */

14
lintmain.c Normal file
View File

@ -0,0 +1,14 @@
/*
* lintmain.c: Main routine for xmllint
*
* See Copyright for the status of this software.
*/
#include <stdio.h>
#include "private/lint.h"
int
main(int argc, char **argv) {
return(xmllintMain(argc, (const char **) argv, stderr, NULL));
}

View File

@ -494,7 +494,7 @@ meson.override_dependency('libxml-2.0', xml_dep)
executable(
'xmllint',
files('xmllint.c', 'shell.c'),
files('xmllint.c', 'shell.c', 'lintmain.c'),
dependencies: [xml_dep, xmllint_deps],
include_directories: config_dir,
install: true,

View File

@ -35,7 +35,7 @@
#include <libxml/relaxng.h>
#endif
#include "private/shell.h"
#include "private/lint.h"
#ifndef STDIN_FILENO
#define STDIN_FILENO 0

View File

@ -67,7 +67,7 @@
#include <libxml/xmlsave.h>
#endif
#include "private/shell.h"
#include "private/lint.h"
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
@ -2201,7 +2201,6 @@ parseAndPrintFile(xmllintState *lint, const char *filename) {
}
#endif
#ifndef XMLLINT_FUZZ
/*
* shell interaction
*/
@ -2212,7 +2211,6 @@ parseAndPrintFile(xmllintState *lint, const char *filename) {
xmllintShell(doc, filename, stdout);
goto done;
}
#endif
#ifdef LIBXML_XPATH_ENABLED
if (lint->xpathquery != NULL) {
@ -3234,7 +3232,7 @@ xmllintParseOptions(xmllintState *lint, int argc, const char **argv) {
return(XMLLINT_RETURN_OK);
}
static int
int
xmllintMain(int argc, const char **argv, FILE *errStream,
xmlResourceLoader loader) {
xmllintState state, *lint;
@ -3545,10 +3543,3 @@ error:
return(lint->progresult);
}
#ifndef XMLLINT_FUZZ
int
main(int argc, char **argv) {
return(xmllintMain(argc, (const char **) argv, stderr, NULL));
}
#endif