All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] dbus: Close unused file descriptors when creating message
@ 2016-05-04 11:03 Andrew Zaborowski
  2016-05-04 11:03 ` [PATCH 2/4] unit: End to end FD passing test Andrew Zaborowski
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2016-05-04 11:03 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1844 bytes --]

---
 ell/dbus-message.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/ell/dbus-message.c b/ell/dbus-message.c
index 0fe76de..89aaacc 100644
--- a/ell/dbus-message.c
+++ b/ell/dbus-message.c
@@ -765,7 +765,7 @@ struct l_dbus_message *dbus_message_from_blob(const void *data, size_t size,
 					'g', &message->signature);
 
 	if (num_fds) {
-		uint32_t unix_fds;
+		uint32_t unix_fds, orig_fds = num_fds;
 
 		if (!get_header_field(message, DBUS_MESSAGE_FIELD_UNIX_FDS,
 					'u', &unix_fds))
@@ -774,12 +774,11 @@ struct l_dbus_message *dbus_message_from_blob(const void *data, size_t size,
 		if (num_fds > unix_fds)
 			num_fds = unix_fds;
 
-		if (num_fds > L_ARRAY_SIZE(message->fds)) {
-			for (i = L_ARRAY_SIZE(message->fds); i < num_fds; i++)
-				close(fds[i]);
-
+		if (num_fds > L_ARRAY_SIZE(message->fds))
 			num_fds = L_ARRAY_SIZE(message->fds);
-		}
+
+		for (i = num_fds; i < orig_fds; i++)
+			close(fds[i]);
 	}
 
 	message->num_fds = num_fds;
@@ -824,7 +823,7 @@ struct l_dbus_message *dbus_message_build(void *header, size_t header_size,
 	message->sealed = true;
 
 	if (num_fds) {
-		uint32_t unix_fds;
+		uint32_t unix_fds, orig_fds = num_fds;
 
 		if (!get_header_field(message, DBUS_MESSAGE_FIELD_UNIX_FDS,
 					'u', &unix_fds)) {
@@ -835,12 +834,11 @@ struct l_dbus_message *dbus_message_build(void *header, size_t header_size,
 		if (num_fds > unix_fds)
 			num_fds = unix_fds;
 
-		if (num_fds > L_ARRAY_SIZE(message->fds)) {
-			for (i = L_ARRAY_SIZE(message->fds); i < num_fds; i++)
-				close(fds[i]);
-
+		if (num_fds > L_ARRAY_SIZE(message->fds))
 			num_fds = L_ARRAY_SIZE(message->fds);
-		}
+
+		for (i = num_fds; i < orig_fds; i++)
+			close(fds[i]);
 	}
 
 	message->num_fds = num_fds;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-04 16:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-04 11:03 [PATCH 1/4] dbus: Close unused file descriptors when creating message Andrew Zaborowski
2016-05-04 11:03 ` [PATCH 2/4] unit: End to end FD passing test Andrew Zaborowski
2016-05-04 16:09   ` Denis Kenzior
2016-05-04 11:03 ` [PATCH 3/4] unit: Add UNIX_FDS header fields in FD test messages Andrew Zaborowski
2016-05-04 16:10   ` Denis Kenzior
2016-05-04 11:03 ` [PATCH 4/4] dbus: Handle partial reads and writes Andrew Zaborowski
2016-05-04 11:10   ` Andrzej Zaborowski
2016-05-04 16:38   ` Denis Kenzior
2016-05-04 16:05 ` [PATCH 1/4] dbus: Close unused file descriptors when creating message Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.