[Tarantool-patches] [PATCH v1 1/1] sql: fix a segfault in hex() on receiving zeroblob
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Thu Aug 26 23:42:00 MSK 2021
Thanks for the patch!
See 2 comments below.
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index c063552d6..2ff368dc7 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -53,6 +53,49 @@
> +/** Implementation of the HEX() SQL built-in function. */
> +static void
> +func_hex(struct sql_context *ctx, int argc, struct Mem **argv)
> +{
> + assert(argc == 1);
> + (void)argc;
> + if (argv[0]->type == MEM_TYPE_NULL)
> + return mem_set_null(ctx->pOut);
> +
> + assert(argv[0]->type == MEM_TYPE_BIN && argv[0]->n >= 0);
> + assert((argv[0]->flags & MEM_Zero) == 0 || argv[0]->u.nZero >= 0);
> + uint32_t size = 2 * argv[0]->n;
> + if ((argv[0]->flags & MEM_Zero) != 0)
> + size += 2 * argv[0]->u.nZero;
> + if (size == 0)
> + return mem_set_str0_static(ctx->pOut, "");
> +
> + char *str = sqlDbMallocRawNN(sql_get(), size);
> + if (str == NULL) {
> + ctx->is_aborted = true;
> + return;
> + }
> + for (int i = 0; i < argv[0]->n; ++i) {
> + char c = argv[0]->z[i];
> + str[2 * i] = hexdigits[(c >> 4) & 0xf];
> + str[2 * i + 1] = hexdigits[c & 0xf];
> + }
> + if ((argv[0]->flags & MEM_Zero) != 0) {
> + for (int i = 0; i < argv[0]->u.nZero; ++i) {
> + int j = argv[0]->n + i;
> + str[2 * j] = '0';
> + str[2 * j + 1] = '0';
1. The same as for the patch for 2.8 branch.
> + }
> + }
> + mem_set_str_allocated(ctx->pOut, str, size);
> +}
> @@ -2034,7 +2042,7 @@ static struct sql_func_definition definitions[] = {
> {"GROUP_CONCAT", 2, {FIELD_TYPE_VARBINARY, FIELD_TYPE_VARBINARY},
> FIELD_TYPE_VARBINARY, groupConcatStep, groupConcatFinalize},
>
> - {"HEX", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_STRING, hexFunc, NULL},
> + {"HEX", 1, {FIELD_TYPE_VARBINARY}, FIELD_TYPE_STRING, func_hex, NULL},
2. What is the final name pattern? I see among new function names
- trim_func - 'func' suffix
- sql_func_uuid, sql_func_version - 'sql_func' prefix
- sql_builtin_stub - 'sql' prefix
- sum_step - no prefixes or suffixes
now you add a fifth way:
- func_hex - 'func' prefix.
I suggest to choose one way to use for all new function names.
More information about the Tarantool-patches
mailing list