Skip to content

Commit f16960f

Browse files
committed
schema: update parsing _space system space
* Add support is_nullable to parsing _space system space. * Add the check of a field type. * Replace string comparation. It's no always correct and safe to use memcmp to compare a null-terminated string with a length specified string, because it doesn't check the end of null-terminated string (like strncmp) which may be less.
1 parent 20a62e1 commit f16960f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/tarantool_schema.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,25 @@ parse_schema_space_value_value(struct schema_field_value *fld,
265265
if (mp_typeof(**tuple) != MP_STR)
266266
goto error;
267267
const char *sfield = mp_decode_str(tuple, &sfield_len);
268-
if (memcmp(sfield, "name", sfield_len) == 0) {
268+
if (strncmp_strict(sfield, sfield_len, "name")) {
269269
if (mp_typeof(**tuple) != MP_STR)
270270
goto error;
271271
sfield = mp_decode_str(tuple, &fld->field_name_len);
272272
fld->field_name = pemalloc(fld->field_name_len, 1);
273273
if (!fld->field_name)
274274
goto error;
275275
memcpy(fld->field_name, sfield, fld->field_name_len);
276-
} else if (memcmp(sfield, "type", sfield_len) == 0) {
276+
} else if (strncmp_strict(sfield, sfield_len, "type")) {
277277
if (mp_typeof(**tuple) != MP_STR)
278278
goto error;
279279
sfield = mp_decode_str(tuple, &sfield_len);
280280
fld->field_type = field_type_by_name(sfield, sfield_len);
281+
if (fld->field_type == field_type_MAX)
282+
goto error;
283+
} else if (strncmp_strict(sfield, sfield_len, "is_nullable")) {
284+
if (mp_typeof(**tuple) != MP_BOOL)
285+
goto error;
286+
fld->is_nullable = mp_decode_bool(tuple);
281287
} else {
282288
mp_next(tuple);
283289
}
@@ -313,6 +319,7 @@ parse_schema_space_value(struct schema_space_value *space_string,
313319
int i = 0;
314320
for (i = 0; i < fmt_len; ++i) {
315321
struct schema_field_value *val = &(space_string->schema_list[i]);
322+
*val = field_val_def;
316323
if (mp_typeof(**tuple) != MP_MAP)
317324
goto error;
318325
uint32_t arrsz = mp_decode_map(tuple);

0 commit comments

Comments
 (0)