All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH v3 4/9] gvariant: Fix empty structure/array parsing and error check
Date: Mon, 18 Apr 2016 14:39:56 -0500	[thread overview]
Message-ID: <5715380C.8030604@gmail.com> (raw)
In-Reply-To: <1460680442-15201-4-git-send-email-andrew.zaborowski@intel.com>

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

Hi Andrew,

On 04/14/2016 07:33 PM, Andrew Zaborowski wrote:
> Allow empty signatures in _gvariant_num_children and check the return
> value for errors or we might crash.
> ---
>   ell/gvariant-util.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/ell/gvariant-util.c b/ell/gvariant-util.c
> index e07bd2f..791fc41 100644
> --- a/ell/gvariant-util.c
> +++ b/ell/gvariant-util.c
> @@ -201,14 +201,14 @@ int _gvariant_num_children(const char *sig)
>   	if (strlen(sig) > 255)
>   		return false;
>
> -	do {
> +	while (*s) {
>   		s = validate_next_type(s, &a);
>
>   		if (!s)
>   			return -1;
>
>   		num_children += 1;
> -	} while (*s);
> +	}
>

So I have a nagging bad feeling about this one.  The code of this 
function was copied from _gvariant_valid_signature.  So changing this 
strongly implies changing _gvariant_valid_signature as well...

Passing in "" won't crash this function, so where do we crash?

>   	return num_children;
>   }
> @@ -374,7 +374,7 @@ static bool gvariant_iter_init_internal(struct l_dbus_message_iter *iter,
>   		unsigned int alignment : 4;
>   		size_t end;		/* Index past the end of the type */
>   	} *children;
> -	uint8_t n_children;
> +	int n_children;
>
>   	if (sig_end) {
>   		size_t len = sig_end - sig_start;
> @@ -392,6 +392,9 @@ static bool gvariant_iter_init_internal(struct l_dbus_message_iter *iter,
>   	iter->pos = 0;
>
>   	n_children = _gvariant_num_children(subsig);
> +	if (n_children < 0)
> +		return false;
> +
>   	children = l_new(struct gvariant_type_info, n_children);

So why would we be allocating a zero-sized array?  Do we need to special 
case this somehow?

Can I get some unit test data to play with?

>
>   	for (p = sig_start, i = 0; i < n_children; i++) {
>

Regards,
-Denis

  reply	other threads:[~2016-04-18 19:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15  0:33 [PATCH v3 1/9] dbus: Update GVariant message header format Andrew Zaborowski
2016-04-15  0:33 ` [PATCH v3 2/9] dbus: Don't rely on 1st KDBUS_ITEM_PAYLOAD_OFF being the header Andrew Zaborowski
2016-04-18 16:52   ` Denis Kenzior
2016-04-15  0:33 ` [PATCH v3 3/9] gvariant: New gvariant message format support Andrew Zaborowski
2016-04-18 19:25   ` Denis Kenzior
2016-04-15  0:33 ` [PATCH v3 4/9] gvariant: Fix empty structure/array parsing and error check Andrew Zaborowski
2016-04-18 19:39   ` Denis Kenzior [this message]
2016-04-22  0:01     ` Andrzej Zaborowski
2016-04-22  0:29       ` Andrzej Zaborowski
2016-04-22  2:06         ` Denis Kenzior
2016-04-22  2:32       ` Denis Kenzior
2016-04-22 10:30         ` Andrzej Zaborowski
2016-04-15  0:33 ` [PATCH v3 5/9] gvariant: Fix empty struct encoding Andrew Zaborowski
2016-04-18 19:33   ` Denis Kenzior
2016-04-15  0:33 ` [PATCH v3 6/9] dbus: Fix the kdbus message encoding Andrew Zaborowski
2016-04-18 19:25   ` Denis Kenzior
2016-04-15  0:34 ` [PATCH v3 7/9] dbus: Remove signature field from gvariant header Andrew Zaborowski
2016-04-18 16:59   ` Denis Kenzior
2016-04-21 23:46     ` Andrzej Zaborowski
2016-04-15  0:34 ` [PATCH v3 8/9] unit: Update GVariant test messages Andrew Zaborowski
2016-04-18 17:05   ` Denis Kenzior
2016-04-15  0:34 ` [PATCH v3 9/9] dbus: Rename _dbus_header_is_valid to _dbus1_header_is_valid Andrew Zaborowski
2016-04-18 16:53   ` Denis Kenzior
2016-04-18 16:52 ` [PATCH v3 1/9] dbus: Update GVariant message header format 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=5715380C.8030604@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.