Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Chris Sosnin <k.sosnin@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2] tuple: fix non-informative update() error message
Date: Sat, 30 Nov 2019 00:25:09 +0100	[thread overview]
Message-ID: <874875d2-9976-5e97-4898-9f2b6ddfe3fd@tarantool.org> (raw)
In-Reply-To: <20191128122815.15968-1-k.sosnin@tarantool.org>

Hi! Thanks for the fixes!

On 28/11/2019 13:28, Chris Sosnin wrote:
> Hi! Thank you for your suggestions.
> I am sorry for being impatient.
> 
>> 1. To not duplicate code, you can add a label, and make a
>> goto to there from 'default'. Or vice versa - go to default
>> from there.
> 
> I labeled the first return as error:
> 
> +error:
> +		diag_set(ClientError, ER_UNKNOWN_UPDATE_OP, op_num,
> +			 tt_sprintf("\"%.*s\"", len, opcode));
> +		return NULL;
> +	}
> ...
> default:
> -		diag_set(ClientError, ER_UNKNOWN_UPDATE_OP);
> -		return NULL;
> +		goto error;
> }
> 
>> 2. I would better assign it after xrow_update_op_by()
>> returned not NULL. Because MessagePack strings are not
>> zero terminated. So 'opcode' after mp_decode_str() may
>> actually point at invalid memory instead of zero
>> terminator in case of an empty string.
> 
> In this case we would still return with an error, however
> I changed it to be your way:

It will return an error, yes. In case the dereference of
the invalid pointer won't crash by luck.

> 
> +	const char *opcode = mp_decode_str(expr, &len);
> +	op->meta = xrow_update_op_by(opcode, len, op_num);
>  	if (op->meta == NULL)
>  		return -1;
> +	op->opcode = *opcode;
> 
> diff --git a/src/box/xrow_update.c b/src/box/xrow_update.c
> index 123db081a..db215aada 100644
> --- a/src/box/xrow_update.c
> +++ b/src/box/xrow_update.c
> @@ -620,12 +625,16 @@ xrow_update_op_decode(struct xrow_update_op *op, int index_base,
>  			 "update operation name must be a string");
>  		return -1;
>  	}
> -	op->opcode = *mp_decode_str(expr, &len);
> -	op->meta = xrow_update_op_by(op->opcode);
> +	const char *opcode = mp_decode_str(expr, &len);
> +	op->meta = xrow_update_op_by(opcode, len, op_num);
>  	if (op->meta == NULL)
>  		return -1;
> +	op->opcode = *opcode;
>  	if (arg_count != op->meta->arg_count) {
> -		diag_set(ClientError, ER_UNKNOWN_UPDATE_OP);
> +		const char *str = tt_sprintf("wrong number of arguments, "\
> +		                 "expected %u, got %u",
> +		                 op->meta->arg_count, arg_count);

Seems like the comment 3 from the previous review is not
fixed. The indentation is still incorrect here.

> +		diag_set(ClientError, ER_UNKNOWN_UPDATE_OP, op_num, str);
>  		return -1;
>  	}
>  	int32_t field_no = 0;

  reply	other threads:[~2019-11-29 23:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27  8:53 Chris Sosnin
2019-11-27 22:55 ` Vladislav Shpilevoy
2019-11-28 12:28   ` Chris Sosnin
2019-11-29 23:25     ` Vladislav Shpilevoy [this message]
2019-11-30  0:09       ` Chris Sosnin
2019-11-30  1:04         ` Vladislav Shpilevoy

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=874875d2-9976-5e97-4898-9f2b6ddfe3fd@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=k.sosnin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2] tuple: fix non-informative update() error message' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox