From: Francois-Xavier Le Bail Date: Mon, 12 Oct 2015 20:17:01 +0000 (+0200) Subject: Fix the error handling in 'ndo_printf' function X-Git-Tag: tcpdump-4.8.0~92 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/a1dadfb1bc7951c409c0f453321b9171bb8607b6 Fix the error handling in 'ndo_printf' function Moreover: Replace strerror() calls with pcap_strerror() calls, in case some platform lacks strerror(). --- diff --git a/print.c b/print.c index ee8ee97b..9fedd9fb 100644 --- a/print.c +++ b/print.c @@ -462,6 +462,8 @@ ndo_printf(netdissect_options *ndo _U_, const char *fmt, ...) ret = vfprintf(stdout, fmt, args); va_end(args); + if (ret < 0) + ndo_error(ndo, "Unable to write output: %s", pcap_strerror(errno)); return (ret); } diff --git a/tcpdump.c b/tcpdump.c index de0054ec..3fe14844 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -1247,7 +1247,7 @@ main(int argc, char **argv) VFile = fopen(VFileName, "r"); if (VFile == NULL) - error("Unable to open file: %s\n", strerror(errno)); + error("Unable to open file: %s\n", pcap_strerror(errno)); ret = get_next_file(VFile, VFileLine); if (!ret) @@ -1906,7 +1906,7 @@ compress_savefile(const char *filename) "compress_savefile:execlp(%s, %s): %s\n", zflag, filename, - strerror(errno)); + pcap_strerror(errno)); # ifdef HAVE_FORK exit(1); # else