Fixes to chkprintcap:

- Check the return from a call to malloc() in skim_printcap(), and
  return a NULL if that fails.
- Fix a small memory leak in main() that happens if skim_printcap()
  returns an error, including the new error-return of NULL.

Submitted by:	Tom Rix <trix@juniper.net>
Reviewed by:	pfg, ngie
MFC after:	4 weeks
Sponsored by:	Dell EMC Isilon, Juniper
Differential Revision:	D9954, D9982
This commit is contained in:
Garance A Drosehn 2017-03-20 22:36:28 +00:00
parent f3e05661e1
commit e550d65c85
2 changed files with 12 additions and 2 deletions

View File

@ -113,8 +113,13 @@ main(int argc, char **argv)
* the printcap file.
*/
skres = skim_printcap(pcap_fname, verbosity);
if (skres->fatalerr)
return (skres->fatalerr);
if (skres == NULL) {
problems = 1;
goto main_ret;
} else if (skres->fatalerr) {
problems = skres->fatalerr;
goto main_ret;
}
/*
* Now use the standard capability-db routines to check the values
@ -156,6 +161,9 @@ main(int argc, char **argv)
warnx("WARNING: but only found %d queues to process!",
queuecnt);
}
main_ret:
free(pcap_fname);
return (problems);
}

View File

@ -82,6 +82,8 @@ skim_printcap(const char *pcap_fname, int verbosity)
enum {CMNT_LINE, ENTRY_LINE, TAB_LINE, TABERR_LINE} is_type, had_type;
skinf = malloc(sizeof(struct skiminfo));
if (skinf == NULL)
return (NULL);
memset(skinf, 0, sizeof(struct skiminfo));
pc_file = fopen(pcap_fname, "r");