From 48b44ee3e2d98f51368243de8e19e2d78de5c7ed Mon Sep 17 00:00:00 2001 From: Akash Chandra Date: Fri, 10 Jan 2025 09:06:53 +0530 Subject: [PATCH 1/5] deps: update submodules --- modules/c-client | 2 +- modules/libyaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/c-client b/modules/c-client index f7af9db2..8f48d1d1 160000 --- a/modules/c-client +++ b/modules/c-client @@ -1 +1 @@ -Subproject commit f7af9db267abe6d61bd6a2b6fc2424d3687e6d7d +Subproject commit 8f48d1d1dc97834a906a3aae5ddff271b999500b diff --git a/modules/libyaml b/modules/libyaml index 2c891fc7..840b65c4 160000 --- a/modules/libyaml +++ b/modules/libyaml @@ -1 +1 @@ -Subproject commit 2c891fc7a770e8ba2fec34fc6b545c672beb37e6 +Subproject commit 840b65c40675e2d06bf40405ad3f12dec7f35923 From 511671aa33378f80a4caea6c9da2852bcf649785 Mon Sep 17 00:00:00 2001 From: Akash Chandra Date: Fri, 17 Jan 2025 09:26:00 +0530 Subject: [PATCH 2/5] debug: comment a map based test case --- src/test/unit/obj_spec_parse_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/obj_spec_parse_test.c b/src/test/unit/obj_spec_parse_test.c index 2ef10dff..f42ae582 100644 --- a/src/test/unit/obj_spec_parse_test.c +++ b/src/test/unit/obj_spec_parse_test.c @@ -207,7 +207,7 @@ _test_valid(const char* obj_spec_str, as_record_init(&rec, obj_spec_n_bins(&o)); ck_assert_int_eq(obj_spec_populate_bins(&o, &rec, &random, "test", write_bins, n_write_bins, 1.f), 0); - _dbg_obj_spec_assert_valid(&o, &rec, write_bins, n_write_bins, "test"); + // _dbg_obj_spec_assert_valid(&o, &rec, write_bins, n_write_bins, "test"); val = obj_spec_gen_value(&o, &random2, write_bins, n_write_bins); ck_assert_ptr_ne(val, NULL); From 661fa956fa4af8a375a699dbfa67cc43cba83187 Mon Sep 17 00:00:00 2001 From: Akash Chandra Date: Fri, 17 Jan 2025 10:26:14 +0530 Subject: [PATCH 3/5] revert changes for test case --- src/test/unit/obj_spec_parse_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/obj_spec_parse_test.c b/src/test/unit/obj_spec_parse_test.c index f42ae582..2ef10dff 100644 --- a/src/test/unit/obj_spec_parse_test.c +++ b/src/test/unit/obj_spec_parse_test.c @@ -207,7 +207,7 @@ _test_valid(const char* obj_spec_str, as_record_init(&rec, obj_spec_n_bins(&o)); ck_assert_int_eq(obj_spec_populate_bins(&o, &rec, &random, "test", write_bins, n_write_bins, 1.f), 0); - // _dbg_obj_spec_assert_valid(&o, &rec, write_bins, n_write_bins, "test"); + _dbg_obj_spec_assert_valid(&o, &rec, write_bins, n_write_bins, "test"); val = obj_spec_gen_value(&o, &random2, write_bins, n_write_bins); ck_assert_ptr_ne(val, NULL); From 62de2f9c95c7c5c0b247ef23ae3c5c2b817a07e4 Mon Sep 17 00:00:00 2001 From: Akash Chandra Date: Thu, 30 Jan 2025 10:36:10 +0530 Subject: [PATCH 4/5] fix: Map keys cannot be double --- src/main/object_spec.c | 6 +++++ src/test/unit/obj_spec_parse_test.c | 38 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/object_spec.c b/src/main/object_spec.c index 0f2c1bb8..b20d2905 100644 --- a/src/main/object_spec.c +++ b/src/main/object_spec.c @@ -1160,6 +1160,12 @@ _parse_bin_types(as_vector* bin_specs, uint32_t* n_bins, break; } case 'D': + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { + _print_parse_error("Map key cannot be double", + obj_spec_str, str); + _destroy_consumer_states(state); + return -1; + } bin_spec->type = BIN_SPEC_TYPE_DOUBLE; str++; break; diff --git a/src/test/unit/obj_spec_parse_test.c b/src/test/unit/obj_spec_parse_test.c index 2ef10dff..6517f8e3 100644 --- a/src/test/unit/obj_spec_parse_test.c +++ b/src/test/unit/obj_spec_parse_test.c @@ -438,11 +438,11 @@ DEFINE_TCASE(test_map_II, "{I1:I2}"); DEFINE_TCASE(test_map_ID, "{I1:D}"); DEFINE_TCASE(test_map_IS, "{I1:S4}"); DEFINE_TCASE(test_map_IB, "{I1:B5}"); -DEFINE_TCASE(test_map_Db, "{D:b}"); -DEFINE_TCASE(test_map_DI, "{D:I2}"); -DEFINE_TCASE(test_map_DD, "{D:D}"); -DEFINE_TCASE(test_map_DS, "{D:S4}"); -DEFINE_TCASE(test_map_DB, "{D:B5}"); +DEFINE_FAILING_TCASE(test_map_Db, "{D:b}", "maps cannot have double keys"); +DEFINE_FAILING_TCASE(test_map_DI, "{D:I2}", "maps cannot have double keys"); +DEFINE_FAILING_TCASE(test_map_DD, "{D:D}", "maps cannot have double keys"); +DEFINE_FAILING_TCASE(test_map_DS, "{D:S4}", "maps cannot have double keys"); +DEFINE_FAILING_TCASE(test_map_DB, "{D:B5}", "maps cannot have double keys"); DEFINE_TCASE(test_map_Sb, "{S2:b}"); DEFINE_TCASE(test_map_SI, "{S2:I2}"); DEFINE_TCASE(test_map_SD, "{S2:D}"); @@ -495,12 +495,12 @@ DEFINE_FAILING_TCASE(test_spaces, "I1 D", "need commas separating tokens"); */ DEFINE_TCASE(test_map_to_list, "{I5:[S10,B20,D,b]}"); DEFINE_TCASE(test_list_of_maps, "[{I5:I1},{S10:B20}]"); -DEFINE_TCASE(test_mixed_list_of_maps, "[{D:I3},S10,{S20:B1},b]"); +DEFINE_FAILING_TCASE(test_mixed_list_of_maps, "[{D:I3},S10,{S20:B1},b]", "map cannot have double keys"); DEFINE_TCASE(test_nested_lists, "[[S10,I4,[B10,B5,D],D],S20,[B100,I7,D,b],[[I3],[I4,I5,I6]]]"); -DEFINE_TCASE(test_nested_maps, "{I5:{S30:{D:{B123:b}}}}"); -DEFINE_TCASE(test_nested_mix, - "[{S10:D},[I3,{S10:B20},{I3:{D:[I1,I2,b]}},B10,b],{B32:[b,I3,I5,{I7:D}]}]"); +DEFINE_FAILING_TCASE(test_nested_maps, "{I5:{S30:{D:{B123:b}}}}", "map cannot have double keys"); +DEFINE_FAILING_TCASE(test_nested_mix, + "[{S10:D},[I3,{S10:B20},{I3:{D:[I1,I2,b]}},B10,b],{B32:[b,I3,I5,{I7:D}]}]", "map cannot have double keys"); DEFINE_FAILING_TCASE(test_map_key_list, "{[I3,I5]:I6}", "map key cannot be a list"); DEFINE_FAILING_TCASE(test_map_key_map, "{{S20:I4}:I1}", "map key cannot be a map"); DEFINE_FAILING_TCASE(test_map_to_undeclared_list, "{I4:I1,I2}", "map value must be single type"); @@ -532,7 +532,7 @@ DEFINE_TCASE(test_mult_map, "20*{I6:S20}"); DEFINE_TCASE(test_mult_within_list, "2*[5*I1,3*I2,100*S3]"); DEFINE_TCASE(test_mult_within_map, "30*{I3:[5*S20]}"); DEFINE_TCASE(test_mult_map_key_I, "{3*I2:S3}"); -DEFINE_TCASE(test_mult_map_key_D, "{5*D:S3}"); +DEFINE_FAILING_TCASE(test_mult_map_key_D, "{5*D:S3}", "map cannot have double keys"); DEFINE_TCASE(test_mult_map_key_S, "{2*S2:S3}"); DEFINE_TCASE(test_mult_map_key_B, "{700*B5:S3}"); DEFINE_TCASE(test_mult_map_key_I_high_coverage, "{200*I1:S3}"); @@ -819,11 +819,11 @@ obj_spec_suite(void) tcase_add_ptest(tc_map, test_map_ID); tcase_add_ptest(tc_map, test_map_IS); tcase_add_ptest(tc_map, test_map_IB); - tcase_add_ptest(tc_map, test_map_Db); - tcase_add_ptest(tc_map, test_map_DI); - tcase_add_ptest(tc_map, test_map_DD); - tcase_add_ptest(tc_map, test_map_DS); - tcase_add_ptest(tc_map, test_map_DB); + tcase_add_ftest(tc_map, test_map_Db); + tcase_add_ftest(tc_map, test_map_DI); + tcase_add_ftest(tc_map, test_map_DD); + tcase_add_ftest(tc_map, test_map_DS); + tcase_add_ftest(tc_map, test_map_DB); tcase_add_ptest(tc_map, test_map_Sb); tcase_add_ptest(tc_map, test_map_SI); tcase_add_ptest(tc_map, test_map_SD); @@ -872,10 +872,10 @@ obj_spec_suite(void) tcase_add_checked_fixture(tc_nested, simple_setup, simple_teardown); tcase_add_ptest(tc_nested, test_map_to_list); tcase_add_ptest(tc_nested, test_list_of_maps); - tcase_add_ptest(tc_nested, test_mixed_list_of_maps); + tcase_add_ftest(tc_nested, test_mixed_list_of_maps); tcase_add_ptest(tc_nested, test_nested_lists); - tcase_add_ptest(tc_nested, test_nested_maps); - tcase_add_ptest(tc_nested, test_nested_mix); + tcase_add_ftest(tc_nested, test_nested_maps); + tcase_add_ftest(tc_nested, test_nested_mix); tcase_add_ftest(tc_nested, test_map_key_list); tcase_add_ftest(tc_nested, test_map_key_map); tcase_add_ftest(tc_nested, test_map_to_undeclared_list); @@ -902,7 +902,7 @@ obj_spec_suite(void) tcase_add_ptest(tc_multipliers, test_mult_within_list); tcase_add_ptest(tc_multipliers, test_mult_within_map); tcase_add_ptest(tc_multipliers, test_mult_map_key_I); - tcase_add_ptest(tc_multipliers, test_mult_map_key_D); + tcase_add_ftest(tc_multipliers, test_mult_map_key_D); tcase_add_ptest(tc_multipliers, test_mult_map_key_S); tcase_add_ptest(tc_multipliers, test_mult_map_key_B); tcase_add_ptest(tc_multipliers, test_mult_map_key_I_high_coverage); From cc50e8a3c7f6880ca2dbe05b2243ee4acf3b7cb5 Mon Sep 17 00:00:00 2001 From: Akash Chandra Date: Thu, 30 Jan 2025 11:43:58 +0530 Subject: [PATCH 5/5] fix: map keys should not be boolean or double --- src/main/object_spec.c | 27 ++++++++++++++++++++++++--- src/test/unit/obj_spec_parse_test.c | 8 ++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/object_spec.c b/src/main/object_spec.c index b20d2905..a6f2fb98 100644 --- a/src/main/object_spec.c +++ b/src/main/object_spec.c @@ -81,7 +81,7 @@ LOCAL_HELPER void _destroy_consumer_states(struct consumer_state_s* state); LOCAL_HELPER int _parse_bin_types(as_vector* bin_specs, uint32_t* n_bins, const char* const obj_spec_str); LOCAL_HELPER int _parse_const_val(const char* const obj_spec_str, - const char** stream, struct bin_spec_s* bin_spec, char delim); + const char** stream, struct bin_spec_s* bin_spec, char delim, uint8_t type, uint8_t map_state); LOCAL_HELPER void bin_spec_free(struct bin_spec_s* bin_spec); LOCAL_HELPER as_val* _gen_random_bool(as_random* random); LOCAL_HELPER as_val* _gen_random_int(uint8_t range, as_random* random); @@ -1234,7 +1234,7 @@ _parse_bin_types(as_vector* bin_specs, uint32_t* n_bins, default: { const char* prev_str = str; // try parsing as a constant value - if (_parse_const_val(obj_spec_str, &str, bin_spec, state->delimiter) != 0) { + if (_parse_const_val(obj_spec_str, &str, bin_spec, state->delimiter, state->type, state->state) != 0) { _destroy_consumer_states(state); return -1; } @@ -1382,12 +1382,16 @@ _parse_bin_types(as_vector* bin_specs, uint32_t* n_bins, LOCAL_HELPER int _parse_const_val(const char* const obj_spec_str, - const char** str_ptr, struct bin_spec_s* bin_spec, char delim) + const char** str_ptr, struct bin_spec_s* bin_spec, char delim, uint8_t type, uint8_t map_state) { const char* str = *str_ptr; switch (*str) { case 'T': if (!isalpha(str[1])) { + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { // Reject bool as map key + _print_parse_error("Map key cannot be boolean", obj_spec_str, str); + return -1; + } bin_spec->type = BIN_SPEC_TYPE_BOOL | BIN_SPEC_TYPE_CONST; bin_spec->const_bool.val = as_true; *str_ptr = str + 1; @@ -1395,6 +1399,10 @@ _parse_const_val(const char* const obj_spec_str, } case 't': if (strncasecmp(str, "true", 4) == 0 && !isalpha(str[4])) { + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { // Reject bool as map key + _print_parse_error("Map key cannot be boolean", obj_spec_str, str); + return -1; + } bin_spec->type = BIN_SPEC_TYPE_BOOL | BIN_SPEC_TYPE_CONST; bin_spec->const_bool.val = as_true; *str_ptr = str + 4; @@ -1404,6 +1412,10 @@ _parse_const_val(const char* const obj_spec_str, case 'F': if (!isalpha(str[1])) { + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { // Reject bool as map key + _print_parse_error("Map key cannot be boolean", obj_spec_str, str); + return -1; + } bin_spec->type = BIN_SPEC_TYPE_BOOL | BIN_SPEC_TYPE_CONST; bin_spec->const_bool.val = as_false; *str_ptr = str + 1; @@ -1411,6 +1423,10 @@ _parse_const_val(const char* const obj_spec_str, } case 'f': if (strncasecmp(str, "false", 5) == 0 && !isalpha(str[5])) { + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { // Reject bool as map key + _print_parse_error("Map key cannot be boolean", obj_spec_str, str); + return -1; + } bin_spec->type = BIN_SPEC_TYPE_BOOL | BIN_SPEC_TYPE_CONST; bin_spec->const_bool.val = as_false; *str_ptr = str + 5; @@ -1450,6 +1466,11 @@ _parse_const_val(const char* const obj_spec_str, return -1; } + if (type == CONSUMER_TYPE_MAP && map_state == MAP_KEY) { // Reject double as map key + _print_parse_error("Map key cannot be double", obj_spec_str, str); + return -1; + } + bin_spec->type = BIN_SPEC_TYPE_DOUBLE | BIN_SPEC_TYPE_CONST; as_double_init(&bin_spec->const_double.val, val); diff --git a/src/test/unit/obj_spec_parse_test.c b/src/test/unit/obj_spec_parse_test.c index 6517f8e3..207a750f 100644 --- a/src/test/unit/obj_spec_parse_test.c +++ b/src/test/unit/obj_spec_parse_test.c @@ -395,10 +395,10 @@ DEFINE_FAILING_TCASE(test_const_D_f, "f", "a single 'f' is not a valid float"); DEFINE_FAILING_TCASE(test_const_D_0f, "0f", "floats must always contain a '.'"); DEFINE_FAILING_TCASE(test_const_D_1f, "1f", "floats must always contain a '.'"); -DEFINE_TCASE(test_const_map_key_bool, "{true:S5}"); +DEFINE_FAILING_TCASE(test_const_map_key_bool, "{true:S5}", "maps cannot have boolean keys"); DEFINE_TCASE(test_const_map_key_int, "{10:S5}"); DEFINE_TCASE(test_const_map_key_str, "{\"test_key\":S5}"); -DEFINE_TCASE(test_const_map_key_double, "{3.14f:S5}"); +DEFINE_FAILING_TCASE(test_const_map_key_double, "{3.14f:S5}", "maps cannot have double keys"); DEFINE_FAILING_TCASE(test_const_map_keys, "{5*10:S5}", "constant map keys " "cannot have multipliers"); DEFINE_FAILING_TCASE(test_const_map_key_bool_rep, "{true:S5,I:I,true:B10}", @@ -784,10 +784,10 @@ obj_spec_suite(void) tcase_add_ftest(tc_constants, test_const_D_0f); tcase_add_ftest(tc_constants, test_const_D_1f); - tcase_add_ptest(tc_constants, test_const_map_key_bool); + tcase_add_ftest(tc_constants, test_const_map_key_bool); tcase_add_ptest(tc_constants, test_const_map_key_int); tcase_add_ptest(tc_constants, test_const_map_key_str); - tcase_add_ptest(tc_constants, test_const_map_key_double); + tcase_add_ftest(tc_constants, test_const_map_key_double); tcase_add_ftest(tc_constants, test_const_map_keys); tcase_add_ftest(tc_constants, test_const_map_key_bool_rep); tcase_add_ftest(tc_constants, test_const_map_key_int_rep);