| 57 | } |
| 58 | |
| 59 | static bool tc_parse(cbm_test_config_t *config, const char *bytes, size_t len) { |
| 60 | if (memchr(bytes, '\0', len)) |
| 61 | return false; |
| 62 | yyjson_doc *doc = yyjson_read(bytes, len, 0); |
| 63 | if (!doc) |
| 64 | return false; |
| 65 | bool valid = true; |
| 66 | yyjson_val *root = yyjson_doc_get_root(doc); |
| 67 | yyjson_val *impact = tc_field(root, "test_impact", &valid); |
| 68 | if (!valid || !impact) |
| 69 | goto done; |
| 70 | yyjson_val *version = tc_field(impact, "version", &valid); |
| 71 | if (!yyjson_is_uint(version) || yyjson_get_uint(version) != 1) { |
| 72 | valid = false; |
| 73 | goto done; |
| 74 | } |
| 75 | yyjson_val *tests = tc_field(impact, "tests", &valid); |
| 76 | if (!valid || !tests) |
| 77 | goto done; |
| 78 | yyjson_val *globs = tc_field(tests, "test_globs", &valid); |
| 79 | if (!valid || !globs) |
| 80 | goto done; |
| 81 | if (!yyjson_is_arr(globs)) { |
| 82 | valid = false; |
| 83 | goto done; |
| 84 | } |
| 85 | /* JSON source size bounds decoded pattern bytes plus one newline per |
| 86 | * element. Reject gitignore control records: this list is a union of |
| 87 | * positive patterns, not an ordered include/exclude program. */ |
| 88 | char *patterns = cbm_arena_alloc(&config->arena, len + 1); |
| 89 | if (!patterns) { |
| 90 | valid = false; |
| 91 | goto done; |
| 92 | } |
| 93 | size_t used = 0, index, maximum; |
| 94 | yyjson_val *pattern; |
| 95 | yyjson_arr_foreach(globs, index, maximum, pattern) { |
| 96 | const char *text = yyjson_get_str(pattern); |
| 97 | size_t n = yyjson_get_len(pattern); |
| 98 | if (!text || !n || strlen(text) != n || text[0] == '!' || text[0] == '#' || |
| 99 | memchr(text, '\n', n) || memchr(text, '\r', n) || text[n - 1] == ' ' || |
| 100 | text[n - 1] == '\t' || used > len || n >= len - used) { |
| 101 | valid = false; |
| 102 | goto done; |
| 103 | } |
| 104 | memcpy(patterns + used, text, n); |
| 105 | used += n; |
| 106 | patterns[used++] = '\n'; |
| 107 | } |
| 108 | patterns[used] = '\0'; |
| 109 | config->test_globs = cbm_gitignore_parse(patterns); |
| 110 | if (!config->test_globs) |
| 111 | valid = false; |
| 112 | done: |
| 113 | yyjson_doc_free(doc); |
| 114 | return valid; |
| 115 | } |
| 116 |
no test coverage detected