diff options
author | 2014-03-16 18:09:49 +0000 | |
---|---|---|
committer | 2014-03-16 18:09:49 +0000 | |
commit | ead0b14b883988cef2a2a7451fffc9fdd55cee62 (patch) | |
tree | 43ccd8cdb69b72581af8c30cdd1434c8cff62987 | |
parent | check the inferred path is in /etc/signify (diff) | |
download | wireguard-openbsd-ead0b14b883988cef2a2a7451fffc9fdd55cee62.tar.xz wireguard-openbsd-ead0b14b883988cef2a2a7451fffc9fdd55cee62.zip |
prevent common(?) mistake. can't use a directory as a file
-rw-r--r-- | usr.bin/signify/signify.c | 5 |
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; } |