Add missing fclose(3) of fmemopen(3) stream; it does not modify the data.

This commit is contained in:
Todd C. Miller
2021-02-02 13:58:31 -07:00
parent 2fd4a2ad71
commit 20b3904f4f
3 changed files with 16 additions and 10 deletions

View File

@@ -39,20 +39,22 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
struct eventlog *evlog = NULL;
FILE *fp;
/* Operate in-memory, do not fclose or it will free() data. */
/* Operate in-memory. */
fp = fmemopen((void *)data, size, "r");
if (fp == NULL)
return 0;
/* Parsed contents of an log.json file are stored in evlog. */
if ((evlog = calloc(1, sizeof(*evlog))) == NULL)
return 0;
evlog = calloc(1, sizeof(*evlog));
if (evlog != NULL) {
evlog->runuid = (uid_t)-1;
evlog->rungid = (gid_t)-1;
/* Try to parse buffer as a JSON-format I/O log info file. */
iolog_parse_loginfo_json(fp, "fuzz.json", evlog);
eventlog_free(evlog);
}
fclose(fp);
return 0;
}

View File

@@ -44,7 +44,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (size < 5)
return 0;
/* Operate in-memory, do not fclose or it will free() data. */
/* Operate in-memory. */
sudoersin = fmemopen((void *)data, size, "r");
if (sudoersin == NULL)
return 0;
@@ -53,7 +53,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
init_defaults();
init_parser("sudoers", false, true);
sudoersparse();
/* Cleanup. */
init_parser(NULL, false, true);
fclose(fp);
return 0;
}

View File

@@ -47,7 +47,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (size < 5)
return 0;
/* Operate in-memory, do not fclose or it will free() data. */
/* Operate in-memory. */
fp = fmemopen((void *)data, size, "r");
if (fp == NULL)
return 0;
@@ -59,6 +59,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
/* Cleanup. */
free_parse_tree(&parse_tree);
fclose(fp);
return 0;
}