]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-resolve: workaround for structured initialization to nested structs 9747/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 29 Jul 2018 07:04:56 +0000 (16:04 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 29 Jul 2018 07:05:23 +0000 (16:05 +0900)
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==
```

src/libsystemd/sd-resolve/sd-resolve.c

index 8cf3d7d54b38bcd5220c22e2dd81a9da7578d660..3eb42c59eba36578a9306cd8c0f1a44018f1bb81 100644 (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;