[glib: 1/9] gmessages: Clear address before passing it to getpeername()




commit 7a1a9259a1db88abe13ee13416c6e306567a0fb8
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Apr 28 10:36:37 2022 +0100

    gmessages: Clear address before passing it to getpeername()
    
    This will probably make no functional difference, but will squash a
    warning from scan-build:
    ```
    ../../../../source/glib/glib/gmessages.c:2243:42: warning: The left operand of '==' is a garbage value 
[core.UndefinedBinaryOperatorResult]
      if (err == 0 && addr.storage.ss_family == AF_UNIX)
                      ~~~~~~~~~~~~~~~~~~~~~~ ^
    ```
    
    It seems like a reasonable thing to warn about. Initialising the full
    union to zero should avoid any possibility of undefined behaviour like
    that.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1767

 glib/gmessages.c | 1 +
 1 file changed, 1 insertion(+)
---
diff --git a/glib/gmessages.c b/glib/gmessages.c
index c1fa98cb20..011793556e 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -2238,6 +2238,7 @@ g_log_writer_is_journald (gint output_fd)
   /* Namespaced journals start with `/run/systemd/journal.${name}/` (see
    * `RuntimeDirectory=systemd/journal.%i` in `systemd-journald@.service`. The
    * default journal starts with `/run/systemd/journal/`. */
+  memset (&addr, 0, sizeof (addr));
   addr_len = sizeof(addr);
   err = getpeername (output_fd, &addr.sa, &addr_len);
   if (err == 0 && addr.storage.ss_family == AF_UNIX)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]