Skip to content

Commit

Permalink
sd-resolve: workaround for structured initialization to nested structs
Browse files Browse the repository at this point in the history
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==
```
  • Loading branch information
yuwata committed Jul 29, 2018
1 parent 2a12960 commit b127bc9
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/libsystemd/sd-resolve/sd-resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b127bc9

Please sign in to comment.