summaryrefslogtreecommitdiff
path: root/usr.bin/signify
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-03-16 18:09:50 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-03-16 18:09:50 +0000
commitef36d18028d99995d93950aff6eb141cdb688031 (patch)
tree77e729b8dc2c197ba59b336db9ab33b4f6d0fa30 /usr.bin/signify
parentf575fe73636c0a764f1f31a6cd00cda4fb505cb4 (diff)
prevent common(?) mistake. can't use a directory as a file
Diffstat (limited to 'usr.bin/signify')
-rw-r--r--usr.bin/signify/signify.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c
index 25b7ac6df7e..93b4f20abf0 100644
--- a/usr.bin/signify/signify.c
+++ b/usr.bin/signify/signify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: signify.c,v 1.52 2014/03/16 18:03:19 tedu Exp $ */
+/* $OpenBSD: signify.c,v 1.53 2014/03/16 18:09:49 tedu Exp $ */
/*
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
*
@@ -89,6 +89,7 @@ usage(const char *error)
static int
xopen(const char *fname, int flags, mode_t mode)
{
+ struct stat sb;
int fd;
if (strcmp(fname, "-") == 0) {
@@ -104,6 +105,8 @@ xopen(const char *fname, int flags, mode_t mode)
err(1, "can't open %s for %s", fname,
(flags & O_WRONLY) ? "writing" : "reading");
}
+ if (fstat(fd, &sb) == -1 || S_ISDIR(sb.st_mode))
+ errx(1, "can't use directory as file: %s", fname);
return fd;
}