svn commit: r315655 - head/usr.sbin/lpr/chkprintcap
Garance A Drosehn
gad at FreeBSD.org
Mon Mar 20 22:36:30 UTC 2017
Author: gad
Date: Mon Mar 20 22:36:28 2017
New Revision: 315655
URL: https://svnweb.freebsd.org/changeset/base/315655
Log:
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 at juniper.net>
Reviewed by: pfg, ngie
MFC after: 4 weeks
Sponsored by: Dell EMC Isilon, Juniper
Differential Revision: D9954, D9982
Modified:
head/usr.sbin/lpr/chkprintcap/chkprintcap.c
head/usr.sbin/lpr/chkprintcap/skimprintcap.c
Modified: head/usr.sbin/lpr/chkprintcap/chkprintcap.c
==============================================================================
--- head/usr.sbin/lpr/chkprintcap/chkprintcap.c Mon Mar 20 22:33:22 2017 (r315654)
+++ head/usr.sbin/lpr/chkprintcap/chkprintcap.c Mon Mar 20 22:36:28 2017 (r315655)
@@ -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 @@ next:
warnx("WARNING: but only found %d queues to process!",
queuecnt);
}
+
+main_ret:
+ free(pcap_fname);
return (problems);
}
Modified: head/usr.sbin/lpr/chkprintcap/skimprintcap.c
==============================================================================
--- head/usr.sbin/lpr/chkprintcap/skimprintcap.c Mon Mar 20 22:33:22 2017 (r315654)
+++ head/usr.sbin/lpr/chkprintcap/skimprintcap.c Mon Mar 20 22:36:28 2017 (r315655)
@@ -82,6 +82,8 @@ skim_printcap(const char *pcap_fname, in
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");
More information about the svn-src-all
mailing list