diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c index 807d3298444c..ad6f7ece3dbb 100644 --- a/sys/dev/filemon/filemon.c +++ b/sys/dev/filemon/filemon.c @@ -1,4 +1,4 @@ -/* $NetBSD: filemon.c,v 1.30 2018/06/06 01:49:08 maya Exp $ */ +/* $NetBSD: filemon.c,v 1.31 2019/10/30 18:35:06 sjg Exp $ */ /* * Copyright (c) 2010, Juniper Networks, Inc. * @@ -25,7 +25,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.30 2018/06/06 01:49:08 maya Exp $"); +__KERNEL_RCSID(0, "$NetBSD: filemon.c,v 1.31 2019/10/30 18:35:06 sjg Exp $"); #include #include @@ -315,6 +315,11 @@ filemon_ioctl(struct file * fp, u_long cmd, void *data) error = EBADF; break; } + if ((filemon->fm_fp->f_flag & FWRITE) == 0) { + closef(filemon->fm_fp); + filemon->fm_fp = NULL; + return (EBADF); + } /* Write the file header. */ filemon_comment(filemon); break;