summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 08f0e32)
raw | patch | inline | side by side (parent: 08f0e32)
author | Max Kellermann <max.kellermann@gmail.com> | |
Thu, 21 Sep 2017 08:26:28 +0000 (10:26 +0200) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Thu, 21 Sep 2017 08:26:28 +0000 (10:26 +0200) |
Limit the socklen_t to the real path length, and omit the trailing
null terminator in abstract sockets.
null terminator in abstract sockets.
src/net/resolver.c | patch | blob | history |
diff --git a/src/net/resolver.c b/src/net/resolver.c
index 952c2c930005ced9e169fa926feea3533c71cd93..2df1b5ad99714dcefe2d017237364c18c7f9d41e 100644 (file)
--- a/src/net/resolver.c
+++ b/src/net/resolver.c
#include "resolver.h"
#include "config.h"
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (host[0] == '/' || host[0] == '@') {
#ifndef WIN32
- size_t path_length = strlen(host);
- if (path_length >= sizeof(resolver->saun.sun_path)) {
+ const bool is_abstract = *host == '@';
+ /* sun_path must be null-terminated unless it's an abstract
+ socket */
+ const size_t path_length = strlen(host) + !is_abstract;
+ if (path_length > sizeof(resolver->saun.sun_path)) {
free(resolver);
return NULL;
}
resolver->saun.sun_family = AF_UNIX;
- memcpy(resolver->saun.sun_path, host, path_length + 1);
+ memcpy(resolver->saun.sun_path, host, path_length);
if (host[0] == '@')
/* abstract socket */
resolver->current.family = PF_UNIX;
resolver->current.protocol = 0;
- resolver->current.addrlen = sizeof(resolver->saun);
+ resolver->current.addrlen = sizeof(resolver->saun)
+ - sizeof(resolver->saun.sun_path) + path_length;
resolver->current.addr = (const struct sockaddr *)&resolver->saun;
resolver->type = TYPE_ONE;
#else /* WIN32 */