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==
```
This commit is contained in:
Yu Watanabe 2018-07-29 16:04:56 +09:00
parent 2a12960bcd
commit b127bc99d1
1 changed files with 13 additions and 12 deletions

View File

@ -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;