From a60711fd0073c5a65efd802fa3ec3edd9698f2d8 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Tue, 10 May 2016 20:09:40 +0000 Subject: [PATCH] sdiff(1): Fix potential NULL deref in cleanup path In the presence of the --diff-pid argument, it is possible for 'diffpipe' to be NULL. Only fclose() it if it was initialized. Reported by: Coverity CID: 1355183 Sponsored by: EMC / Isilon Storage Division --- usr.bin/sdiff/sdiff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c index b9facfe5c618..008de5359a31 100644 --- a/usr.bin/sdiff/sdiff.c +++ b/usr.bin/sdiff/sdiff.c @@ -430,7 +430,8 @@ main(int argc, char **argv) /* Close open files and pipe, delete temps */ fclose(file1); fclose(file2); - fclose(diffpipe); + if (diffpipe != NULL) + fclose(diffpipe); if (tmp1) if (unlink(tmp1)) warn("Error deleting %s.", tmp1);