summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2015-12-07 18:23:24 +0000
committerderaadt <deraadt@openbsd.org>2015-12-07 18:23:24 +0000
commitcf9a1b36ad1db6cd9a4e602ff4fb93f22eac64e8 (patch)
tree796bbe81a051dc49e7b5bcc83ab44c8284e62716
parentdelete pointless setlocale(3) call; (diff)
downloadwireguard-openbsd-cf9a1b36ad1db6cd9a4e602ff4fb93f22eac64e8.tar.xz
wireguard-openbsd-cf9a1b36ad1db6cd9a4e602ff4fb93f22eac64e8.zip
use O_EXCL rather than a race
-rw-r--r--usr.sbin/vmctl/vmctl.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c
index b795eb180d7..f5f8cb9e701 100644
--- a/usr.sbin/vmctl/vmctl.c
+++ b/usr.sbin/vmctl/vmctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmctl.c,v 1.6 2015/12/06 02:26:14 reyk Exp $ */
+/* $OpenBSD: vmctl.c,v 1.7 2015/12/07 18:23:24 deraadt Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
@@ -338,21 +338,14 @@ int
create_imagefile(const char *imgfile_path, long imgsize)
{
int fd, ret;
- struct stat sb;
off_t ofs;
char ch = '\0';
/* Refuse to overwrite an existing image */
- bzero(&sb, sizeof(sb));
- if (stat(imgfile_path, &sb) == 0) {
- return (EEXIST);
- }
-
- fd = open(imgfile_path, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
-
- if (fd == -1) {
+ fd = open(imgfile_path, O_RDWR | O_CREAT | O_TRUNC | O_EXCL,
+ S_IRUSR | S_IWUSR);
+ if (fd == -1)
return (errno);
- }
ofs = (imgsize * 1024 * 1024) - 1;