From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 3/5] dbus: Add and validate the UNIX_FDS msg header field
Date: Fri, 29 Apr 2016 18:17:37 -0500 [thread overview]
Message-ID: <5723EB91.7050600@gmail.com> (raw)
In-Reply-To: <1461969842-11704-3-git-send-email-andrew.zaborowski@intel.com>
[-- Attachment #1: Type: text/plain, Size: 3209 bytes --]
Hi Andrew,
On 04/29/2016 05:44 PM, Andrew Zaborowski wrote:
> ---
> ell/dbus-message.c | 50 +++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 39 insertions(+), 11 deletions(-)
>
> diff --git a/ell/dbus-message.c b/ell/dbus-message.c
> index 038d44d..0fe76de 100644
> --- a/ell/dbus-message.c
> +++ b/ell/dbus-message.c
> @@ -764,11 +764,22 @@ struct l_dbus_message *dbus_message_from_blob(const void *data, size_t size,
> get_header_field(message, DBUS_MESSAGE_FIELD_SIGNATURE,
> 'g', &message->signature);
>
> - 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) {
> + uint32_t unix_fds;
>
> - num_fds = L_ARRAY_SIZE(message->fds);
> + if (!get_header_field(message, DBUS_MESSAGE_FIELD_UNIX_FDS,
> + 'u', &unix_fds))
> + goto free;
> +
> + if (num_fds > unix_fds)
> + num_fds = unix_fds;
If num_fds > unix_fds, should all unused fds (e.g. fds[unix_fds ..
num_fds-1] be closed just in case as well?
Also, what if unix_fds > num_fds?
> +
> + if (num_fds > L_ARRAY_SIZE(message->fds)) {
> + for (i = L_ARRAY_SIZE(message->fds); i < num_fds; i++)
> + close(fds[i]);
> +
> + num_fds = L_ARRAY_SIZE(message->fds);
> + }
> }
>
> message->num_fds = num_fds;
> @@ -777,7 +788,8 @@ struct l_dbus_message *dbus_message_from_blob(const void *data, size_t size,
> return message;
>
> free:
> - l_free(message);
> + l_dbus_message_unref(message);
> +
> return NULL;
> }
>
> @@ -809,19 +821,31 @@ struct l_dbus_message *dbus_message_build(void *header, size_t header_size,
> message->header = header;
> message->body_size = body_size;
> message->body = body;
> + message->sealed = true;
>
> - 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) {
> + uint32_t unix_fds;
>
> - num_fds = L_ARRAY_SIZE(message->fds);
> + if (!get_header_field(message, DBUS_MESSAGE_FIELD_UNIX_FDS,
> + 'u', &unix_fds)) {
> + l_free(message);
> + return NULL;
> + }
> +
> + 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]);
> +
> + num_fds = L_ARRAY_SIZE(message->fds);
> + }
> }
>
> message->num_fds = num_fds;
> memcpy(message->fds, fds, num_fds * sizeof(int));
>
> - message->sealed = true;
> -
> /* If the field is absent message->signature will remain NULL */
> get_header_field(message, DBUS_MESSAGE_FIELD_SIGNATURE, 'g',
> &message->signature);
> @@ -1013,6 +1037,10 @@ static void build_header(struct l_dbus_message *message, const char *signature)
> add_field(builder, driver, DBUS_MESSAGE_FIELD_SIGNATURE,
> "g", signature);
>
> + if (message->num_fds)
> + add_field(builder, driver, DBUS_MESSAGE_FIELD_UNIX_FDS,
> + "u", &message->num_fds);
> +
> driver->leave_array(builder);
>
> generated_signature = driver->finish(builder, &message->header,
>
Regards,
-Denis
next prev parent reply other threads:[~2016-04-29 23:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-29 22:43 [PATCH 1/5] dbus: Handle the 'h' type in append_arguments Andrew Zaborowski
2016-04-29 22:43 ` [PATCH 2/5] dbus: Remove memcpy and fix setting of FD_CLOEXEC on FDs Andrew Zaborowski
2016-04-29 23:20 ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 3/5] dbus: Add and validate the UNIX_FDS msg header field Andrew Zaborowski
2016-04-29 23:17 ` Denis Kenzior [this message]
2016-04-29 23:52 ` Andrzej Zaborowski
2016-04-30 1:15 ` Denis Kenzior
2016-04-30 14:58 ` Andrzej Zaborowski
2016-05-02 15:10 ` Denis Kenzior
2016-05-02 22:25 ` Andrzej Zaborowski
2016-05-03 3:17 ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 4/5] unit: Add UNIX_FDS header fields in FD test messages Andrew Zaborowski
2016-04-29 23:20 ` Denis Kenzior
2016-04-29 22:44 ` [PATCH 5/5] unit: End to end FD passing test Andrew Zaborowski
2016-04-29 23:21 ` Denis Kenzior
2016-04-29 23:20 ` [PATCH 1/5] dbus: Handle the 'h' type in append_arguments Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5723EB91.7050600@gmail.com \
--to=denkenz@gmail.com \
--cc=ell@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.