summaryrefslogtreecommitdiff
path: root/sbin/pfctl/pfctl.c
diff options
context:
space:
mode:
authorCedric Berger <cedric@cvs.openbsd.org>2004-04-09 12:42:07 +0000
committerCedric Berger <cedric@cvs.openbsd.org>2004-04-09 12:42:07 +0000
commit166a2e1658bc097fe1406e491200f9b6dac4604d (patch)
treec21c041c7f2a9d11a4ecea8c5078581627e67f6a /sbin/pfctl/pfctl.c
parent31e7eb082672d48e83df935c46a2cfe2bae838fe (diff)
Do not try to load directories. found+ok mpech@
Diffstat (limited to 'sbin/pfctl/pfctl.c')
-rw-r--r--sbin/pfctl/pfctl.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index e13e1f44bfc..d2d127bf60d 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.213 2004/03/20 09:31:42 david Exp $ */
+/* $OpenBSD: pfctl.c,v 1.214 2004/04/09 12:42:06 cedric Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <net/if.h>
#include <netinet/in.h>
@@ -1061,7 +1062,7 @@ pfctl_rules(int dev, char *filename, int opts, char *anchorname,
fin = stdin;
infile = "stdin";
} else {
- if ((fin = fopen(filename, "r")) == NULL) {
+ if ((fin = pfctl_fopen(filename, "r")) == NULL) {
warn("%s", filename);
return (1);
}
@@ -1150,6 +1151,27 @@ _error:
#undef ERRX
}
+FILE *
+pfctl_fopen(const char *name, const char *mode)
+{
+ struct stat st;
+ FILE *fp;
+
+ fp = fopen(name, mode);
+ if (fp == NULL)
+ return (NULL);
+ if (fstat(fileno(fp), &st)) {
+ fclose(fp);
+ return (NULL);
+ }
+ if (S_ISDIR(st.st_mode)) {
+ fclose(fp);
+ errno = EISDIR;
+ return (NULL);
+ }
+ return (fp);
+}
+
int
pfctl_set_limit(struct pfctl *pf, const char *opt, unsigned int limit)
{