MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / fuzz_config

Function fuzz_config

tests/fuzz/cbm_fuzz.c:128–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128static void fuzz_config(const uint8_t *data, size_t size) {
129 if (size < FUZZ_NUL) {
130 return;
131 }
132 char path[FUZZ_PATH_MAX + FUZZ_FILE_NAME_ROOM];
133 const char *ext = data[0] == 't' ? "toml" : data[0] == 'y' ? "yaml" : "json";
134 (void)snprintf(path, sizeof(path), "%s/config.%s", g_dir, ext);
135 FILE *f = cbm_fopen(path, "wb");
136 if (!f) {
137 return;
138 }
139 size_t body = size - FUZZ_NUL;
140 if (body > 0 && fwrite(data + FUZZ_NUL, FUZZ_NUL, body, f) != body) {
141 (void)fclose(f);
142 return;
143 }
144 if (fclose(f) != 0) {
145 return;
146 }
147 switch (data[0]) {
148 case 't':
149 (void)cbm_toml_upsert_managed_block(path, "# BEGIN codebase-memory",
150 "# END codebase-memory", "owned = true\n");
151 (void)cbm_toml_remove_managed_block(path, "# BEGIN codebase-memory",
152 "# END codebase-memory");
153 break;
154 case 'y':
155 (void)cbm_yaml_upsert_mapping_entry(path, "mcp_servers", "codebase-memory",
156 " command: codebase-memory-mcp\n");
157 (void)cbm_yaml_remove_mapping_entry(path, "mcp_servers", "codebase-memory");
158 break;
159 default: {
160 const char *object_path[] = {"mcpServers"};
161 (void)cbm_json_like_upsert_entry(path, object_path, FUZZ_JSON_PATH_LEN, "codebase-memory",
162 "{\"command\":\"codebase-memory-mcp\"}");
163 char *content = NULL;
164 size_t length = 0;
165 if (cbm_json_like_read_document(path, &content, &length) == 0) {
166 free(content);
167 }
168 break;
169 }
170 }
171 (void)unlink(path);
172}
173
174int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
175 switch (g_target) {

Callers 1

LLVMFuzzerTestOneInputFunction · 0.85

Calls 8

cbm_fopenFunction · 0.85
fwriteFunction · 0.85

Tested by

no test coverage detected