summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-resolve
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-07-29 16:04:56 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-07-29 16:05:23 +0900
commitb127bc99d13cede3b1ba6bd8acd936ff7a0d2f31 (patch)
treeb92baa53e2e9e759893f0ab676ad6f82036d32a4 /src/libsystemd/sd-resolve
parent2a12960bcdb90638bf28da237f89383bdd19b344 (diff)
downloadsystemd-b127bc99d13cede3b1ba6bd8acd936ff7a0d2f31.tar.gz
sd-resolve: workaround for structured initialization to nested structs
When a nested struct is initialized by structured initializer, then padding space is not cleared by zero. So, before setting values, this makes explicitly set zero including padding. This fixes the following false positive warning by valgrind: ``` ==492== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s) ==492== at 0x56D0CF7: sendmsg (in /usr/lib64/libpthread-2.27.so) ==492== by 0x4FDD3C5: sd_resolve_getaddrinfo (sd-resolve.c:975) ==492== by 0x110B9E: manager_connect (timesyncd-manager.c:879) ==492== by 0x10B729: main (timesyncd.c:165) ==492== Address 0x1fff0008f1 is on thread 1's stack ==492== in frame #1, created by sd_resolve_getaddrinfo (sd-resolve.c:928) ==492== ```
Diffstat (limited to 'src/libsystemd/sd-resolve')
-rw-r--r--src/libsystemd/sd-resolve/sd-resolve.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c
index 8cf3d7d54b..3eb42c59eb 100644
--- a/src/libsystemd/sd-resolve/sd-resolve.c
+++ b/src/libsystemd/sd-resolve/sd-resolve.c
@@ -226,15 +226,7 @@ static int send_addrinfo_reply(
int _errno,
int _h_errno) {
- AddrInfoResponse resp = {
- .header.type = RESPONSE_ADDRINFO,
- .header.id = id,
- .header.length = sizeof(AddrInfoResponse),
- .ret = ret,
- ._errno = _errno,
- ._h_errno = _h_errno,
- };
-
+ AddrInfoResponse resp = {};
union {
AddrInfoSerialization ais;
uint8_t space[BUFSIZE];
@@ -244,6 +236,15 @@ static int send_addrinfo_reply(
assert(out_fd >= 0);
+ resp = (AddrInfoResponse) {
+ .header.type = RESPONSE_ADDRINFO,
+ .header.id = id,
+ .header.length = sizeof(AddrInfoResponse),
+ .ret = ret,
+ ._errno = _errno,
+ ._h_errno = _h_errno,
+ };
+
if (ret == 0 && ai) {
void *p = &buffer;
struct addrinfo *k;
@@ -280,7 +281,7 @@ static int send_nameinfo_reply(
int _errno,
int _h_errno) {
- NameInfoResponse resp;
+ NameInfoResponse resp = {};
struct iovec iov[3];
struct msghdr mh;
size_t hl, sl;
@@ -931,7 +932,7 @@ _public_ int sd_resolve_getaddrinfo(
sd_resolve_getaddrinfo_handler_t callback, void *userdata) {
_cleanup_(sd_resolve_query_unrefp) sd_resolve_query *q = NULL;
- AddrInfoRequest req;
+ AddrInfoRequest req = {};
struct iovec iov[3];
struct msghdr mh = {};
int r;
@@ -1008,7 +1009,7 @@ _public_ int sd_resolve_getnameinfo(
void *userdata) {
_cleanup_(sd_resolve_query_unrefp) sd_resolve_query *q = NULL;
- NameInfoRequest req;
+ NameInfoRequest req = {};
struct iovec iov[2];
struct msghdr mh;
int r;