Use sudoersrestart() in fuzz_sudoers.c

Since we run the parser multiple times we need to restart it each time.
This commit is contained in:
Todd C. Miller
2021-02-03 12:52:15 -07:00
parent e66b132d76
commit 3237a18ee3
3 changed files with 7 additions and 5 deletions

View File

@@ -40,13 +40,15 @@ open_sudoers(const char *file, bool doedit, bool *keepopen)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FILE *fp;
/* Don't waste time fuzzing tiny inputs. */
if (size < 5)
return 0;
/* Operate in-memory. */
sudoersin = fmemopen((void *)data, size, "r");
if (sudoersin == NULL)
fp = fmemopen((void *)data, size, "r");
if (fp == NULL)
return 0;
/* Parser needs user_shost for the %h escape in @include expansion. */
@@ -55,12 +57,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
/* Initialize defaults and parse sudoers. */
init_defaults();
init_parser("sudoers", false, true);
sudoersrestart(fp);
sudoersparse();
/* Cleanup. */
init_parser(NULL, false, true);
fclose(sudoersin);
sudoersin = NULL;
fclose(fp);
return 0;
}

View File

@@ -314,6 +314,7 @@ extern bool sudoers_strict;
/* toke.l */
YY_DECL;
void sudoersrestart(FILE *);
extern FILE *sudoersin;
extern const char *sudoers_file;
extern char *sudoers;

View File

@@ -100,7 +100,6 @@ static void usage(int);
static void visudo_cleanup(void);
extern void get_hostname(void);
extern void sudoersrestart(FILE *);
/*
* Globals