dbus_message_iter_append_basic: Don't leak signature if appending fd fails 19/199019/1
authorSimon McVittie <smcv@collabora.com>
Tue, 4 Jul 2017 13:13:15 +0000 (14:13 +0100)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Fri, 1 Feb 2019 01:20:54 +0000 (10:20 +0900)
Change-Id: I37ac4d243832476772ffbd822bbf4598e6f8f9a5
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568

dbus/dbus-message.c

index 322155ad5de1ee11b20d724f8a16b0b09cb43080..29b855001b64ebcc5b750544c62cc389b6cb7387 100644 (file)
@@ -2891,20 +2891,22 @@ dbus_message_iter_append_basic (DBusMessageIter *iter,
       int *fds;
       dbus_uint32_t u;
 
+      ret = FALSE;
+
       /* First step, include the fd in the fd list of this message */
       if (!(fds = expand_fd_array(real->message, 1)))
-        return FALSE;
+        goto out;
 
       *fds = _dbus_dup(*(int*) value, NULL);
       if (*fds < 0)
-        return FALSE;
+        goto out;
 
       u = real->message->n_unix_fds;
 
       /* Second step, write the index to the fd */
       if (!(ret = _dbus_type_writer_write_basic (&real->u.writer, DBUS_TYPE_UNIX_FD, &u))) {
         _dbus_close(*fds, NULL);
-        return FALSE;
+        goto out;
       }
 
       real->message->n_unix_fds += 1;
@@ -2923,6 +2925,9 @@ dbus_message_iter_append_basic (DBusMessageIter *iter,
          freed. */
 #else
       ret = FALSE;
+      /* This is redundant (we could just fall through), but it avoids
+       * -Wunused-label in builds that don't HAVE_UNIX_FD_PASSING */
+      goto out;
 #endif
     }
   else
@@ -2930,6 +2935,7 @@ dbus_message_iter_append_basic (DBusMessageIter *iter,
       ret = _dbus_type_writer_write_basic (&real->u.writer, type, value);
     }
 
+out:
   if (!_dbus_message_iter_close_signature (real))
     ret = FALSE;