Skip to content

Commit 28a22ea

Browse files
Shidfarclaude
andcommitted
fix: add memmove bounds check and prepare failure handling
- Add explicit bounds check before memmove header prepend in MCP tool (prevents overflow if safety limit is raised in the future) - Early-return with log_warn if INSERT prepare fails in write_crosslinks (avoids silent O(n^2) no-op loop) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1242f50 commit 28a22ea

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/mcp/mcp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
34903490
char header[128];
34913491
snprintf(header, sizeof(header), "# Cross-Project Links (%d total)\n\n", total);
34923492
int hlen = (int)strlen(header);
3493+
if (pos + hlen >= XL_BUF_SIZE) pos = XL_BUF_SIZE - hlen - 1;
34933494
memmove(buf + hlen, buf, (size_t)pos + 1);
34943495
memcpy(buf, header, (size_t)hlen);
34953496

src/pipeline/pass_crossrepolinks.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ static int write_crosslinks(const char *cache_dir,
232232
"(protocol, identifier, producer_project, producer_qn, producer_file, "
233233
" consumer_project, consumer_qn, consumer_file, confidence, updated_at) "
234234
"VALUES (?,?,?,?,?,?,?,?,?,?);", -1, &ins, NULL);
235+
if (!ins) {
236+
cbm_log_warn("crosslink.prepare_failed", "path", db_path);
237+
sqlite3_close(db);
238+
return -1;
239+
}
235240

236241
sqlite3_exec(db, "BEGIN TRANSACTION;", NULL, NULL, NULL);
237242

0 commit comments

Comments
 (0)