]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: uapi: only make sure socket file is socket
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 26 Sep 2017 13:02:41 +0000 (15:02 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 26 Sep 2017 13:04:07 +0000 (15:04 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/ipc.c

index d0b5a4674ef9e10802a31a357315d69e4d9d298d..45278ecaed0e3a4afcf6759f3d1238f6662e0f77 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -129,11 +129,16 @@ out:
 
 static bool userspace_has_wireguard_interface(const char *interface)
 {
-       FILE *f = userspace_interface_file(interface);
-       if (!f)
+       struct stat sbuf;
+       char path[PATH_MAX] = { 0 };
+
+       if (strchr(interface, '/'))
                return false;
-       fclose(f);
-       return true;
+       if (snprintf(path, sizeof(path) - 1, SOCK_PATH "%s" SOCK_SUFFIX, interface) < 0)
+               return false;
+       if (stat(path, &sbuf) < 0)
+               return false;
+       return S_ISSOCK(sbuf.st_mode);
 }
 
 static int userspace_get_wireguard_interfaces(struct inflatable_buffer *buffer)