From: Guy Harris Date: Mon, 12 Oct 2009 19:58:30 +0000 (-0700) Subject: If bpf_odmcleanup() is being called to clean up after an error, pass it X-Git-Tag: libpcap-1.1.0~68 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/9dd13b012f23cca0ba7061fbff232d29773635c3 If bpf_odmcleanup() is being called to clean up after an error, pass it a null pointer, so that it doesn't overwrite the error string for the error. Make it set the error string only if passed a non-null pointer. --- diff --git a/pcap-bpf.c b/pcap-bpf.c index b0408da2..86d1bee0 100644 --- a/pcap-bpf.c +++ b/pcap-bpf.c @@ -1050,20 +1050,24 @@ bpf_odmcleanup(char *errbuf) char *errstr; if (odm_unlock(odmlockid) == -1) { - if (odm_err_msg(odmerrno, &errstr) == -1) - errstr = "Unknown error"; - snprintf(errbuf, PCAP_ERRBUF_SIZE, - "bpf_load: odm_unlock failed: %s", - errstr); + if (errbuf != NULL) { + if (odm_err_msg(odmerrno, &errstr) == -1) + errstr = "Unknown error"; + snprintf(errbuf, PCAP_ERRBUF_SIZE, + "bpf_load: odm_unlock failed: %s", + errstr); + } return (PCAP_ERROR); } if (odm_terminate() == -1) { - if (odm_err_msg(odmerrno, &errstr) == -1) - errstr = "Unknown error"; - snprintf(errbuf, PCAP_ERRBUF_SIZE, - "bpf_load: odm_terminate failed: %s", - errstr); + if (errbuf != NULL) { + if (odm_err_msg(odmerrno, &errstr) == -1) + errstr = "Unknown error"; + snprintf(errbuf, PCAP_ERRBUF_SIZE, + "bpf_load: odm_terminate failed: %s", + errstr); + } return (PCAP_ERROR); } @@ -1096,7 +1100,7 @@ bpf_load(char *errbuf) if (major == -1) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "bpf_load: genmajor failed: %s", pcap_strerror(errno)); - (void)bpf_odmcleanup(errbuf); + (void)bpf_odmcleanup(NULL); return (PCAP_ERROR); } @@ -1107,7 +1111,7 @@ bpf_load(char *errbuf) snprintf(errbuf, PCAP_ERRBUF_SIZE, "bpf_load: genminor failed: %s", pcap_strerror(errno)); - (void)bpf_odmcleanup(errbuf); + (void)bpf_odmcleanup(NULL); return (PCAP_ERROR); } }