From 3237a18ee3feae91346933c6eb6ca92dad08e1c6 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 3 Feb 2021 12:52:15 -0700 Subject: [PATCH] Use sudoersrestart() in fuzz_sudoers.c Since we run the parser multiple times we need to restart it each time. --- plugins/sudoers/regress/fuzz/fuzz_sudoers.c | 10 ++++++---- plugins/sudoers/sudoers.h | 1 + plugins/sudoers/visudo.c | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/sudoers/regress/fuzz/fuzz_sudoers.c b/plugins/sudoers/regress/fuzz/fuzz_sudoers.c index 8d2700976..7921f7696 100644 --- a/plugins/sudoers/regress/fuzz/fuzz_sudoers.c +++ b/plugins/sudoers/regress/fuzz/fuzz_sudoers.c @@ -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; } diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 731f4114a..b8e5019ac 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -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; diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 6fd3c8386..8d40f332c 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -100,7 +100,6 @@ static void usage(int); static void visudo_cleanup(void); extern void get_hostname(void); -extern void sudoersrestart(FILE *); /* * Globals