wg: fixup errno handling

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-02-17 19:39:26 +01:00
parent ca5d2708e0
commit d29e0bad7d
2 changed files with 8 additions and 8 deletions

View File

@ -78,7 +78,6 @@ struct wgdevice {
#define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer) #define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer)
#define for_each_wgallowedip(__peer, __allowedip) for ((__allowedip) = (__peer)->first_allowedip; (__allowedip); (__allowedip) = (__allowedip)->next_allowedip) #define for_each_wgallowedip(__peer, __allowedip) for ((__allowedip) = (__peer)->first_allowedip; (__allowedip); (__allowedip) = (__allowedip)->next_allowedip)
#define max(a, b) ((a) > (b) ? (a) : (b))
static inline void free_wgdevice(struct wgdevice *dev) static inline void free_wgdevice(struct wgdevice *dev)
{ {

View File

@ -48,7 +48,6 @@
#define SOCKET_BUFFER_SIZE 8192 #define SOCKET_BUFFER_SIZE 8192
#endif #endif
struct inflatable_buffer { struct inflatable_buffer {
char *buffer; char *buffer;
char *next; char *next;
@ -57,6 +56,7 @@ struct inflatable_buffer {
size_t pos; size_t pos;
}; };
#define max(a, b) ((a) > (b) ? (a) : (b))
static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer) static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer)
{ {
size_t len, expand_to; size_t len, expand_to;
@ -111,7 +111,7 @@ static FILE *userspace_interface_file(const char *interface)
int fd = -1, ret; int fd = -1, ret;
FILE *f = NULL; FILE *f = NULL;
ret = -EINVAL; errno = EINVAL;
if (strchr(interface, '/')) if (strchr(interface, '/'))
goto out; goto out;
ret = snprintf(addr.sun_path, sizeof(addr.sun_path), SOCK_PATH "%s" SOCK_SUFFIX, interface); ret = snprintf(addr.sun_path, sizeof(addr.sun_path), SOCK_PATH "%s" SOCK_SUFFIX, interface);
@ -120,7 +120,7 @@ static FILE *userspace_interface_file(const char *interface)
ret = stat(addr.sun_path, &sbuf); ret = stat(addr.sun_path, &sbuf);
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = -EBADF; errno = EBADF;
if (!S_ISSOCK(sbuf.st_mode)) if (!S_ISSOCK(sbuf.st_mode))
goto out; goto out;
@ -135,12 +135,13 @@ static FILE *userspace_interface_file(const char *interface)
goto out; goto out;
} }
f = fdopen(fd, "r+"); f = fdopen(fd, "r+");
if (!f) if (f)
ret = -errno; errno = 0;
out: out:
if (ret && fd >= 0) ret = -errno;
close(fd);
if (ret) { if (ret) {
if (fd >= 0)
close(fd);
errno = -ret; errno = -ret;
return NULL; return NULL;
} }