ailogic
Find logic bugs in C code for radare2 by analyzing control flow, state transitions, and silent assumptions.
от radareorg★ 23 звезды на GitHub
Установить ailogic в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Introduction
Logic bugs are not syntax errors and the compiler will not catch them. They live in branches that look reasonable, in loops that almost terminate, and in assumptions that are never written down. This skill focuses on radare2's C codebase, where most logic bugs come from misuse of libr APIs, unchecked return values, and state that leaks across calls.
When this skill is used: read AGENTS.md first and follow the project rules. Patches must be surgical, behavior-preserving, and small.
Steps
Understand the function contract before reading the body
- What does each input represent? What range is valid?
- What must always be true on entry and on exit?
- If the contract is unclear, the function is already suspicious.
Identify inputs and boundaries
- Check handling of
NULL, zero, negative, andUT64_MAX/UT32_MAXsentinels. - Look for missing validation at
R_APIentry points (these should useR_RETURN_*). - Static helpers should rely on the contract instead of re-checking.
- Check handling of
Trace control flow with radare2
aaa pdf @ sym.function_name VV @ sym.function_name- Follow every branch, including the implicit
else. - Watch for missing
default:inswitch, fallthrough withoutR_FALLTHROUGH, and early returns that skip cleanup.
- Follow every branch, including the implicit
Track variable state
- Where is each variable initialized, mutated, and consumed?
- Is it reused across iterations without reset?
- Use
afvdto inspect locals and arguments.
Analyze loops
- Off-by-one:
i <= sizevsi < size. - Termination: is the loop variable always advancing?
- Invariants: indices in bounds, pointers still valid, ownership unchanged.
- Clamp sizes once before the loop instead of re-checking inside.
- Off-by-one:
Verify return values and error paths
- Are all
r_*calls checked when they can fail (allocation, IO, parse)? - Does every path return a meaningful value? Does failure free what success would have kept?
- Macros like
R_NEW/R_NEW0never return NULL (compile-time constant size), so do not add checks for them. - Some mutators cannot report failure at all:
RVec*_push_backandset_u_addreturn void and drop the element on OOM. UseRVec*_emplace_backand check the returned slot, or re-test withset_u_contains, wherever the caller's invariant needs the element to be present. - A partially built table, set, or index is worse than none: on any element failure, free it and return the empty case, so callers fall back to their conservative path instead of trusting incomplete data.
- Are all
Hunt silent assumptions
- "The list is non-empty", "the buffer is NUL-terminated", "the offset is aligned", "the seek will succeed".
- Each unchecked assumption is a candidate bug. Confirm it from the call sites, not from wishful thinking.
Confirm dynamically when possible
ood db sym.function_name dc dr; pxDrive the suspect path with a real input and observe the state. A reproducer beats any amount of static reasoning.
Reduce to a minimal case
- Strip unrelated logic, build the smallest r2 oneliner or test that triggers it, then file or fix.
Common logic bug patterns in radare2
- Off-by-one on block size, instruction count, or string length
- Missing branch in a
switchover an enum that grew a new value - Boolean logic inverted after a refactor (
!dropped or doubled) - State not reset between calls because a static or
core->field leaks across invocations - A scoped fact moved from a parameter onto long-lived state, then read after the branch that set it has ended
- Return value of
r_io_read_at/r_buf_read_atignored, partial reads treated as full r_core_cmd*return value ignored when the command can fail- Seek not restored after a temporary
r_core_seek; prefercall_ator the'@addr'cmdform - Iterator invalidated mid-loop by
r_list_deleteinstead ofr_list_delete_iter - CFG walk assuming reducible flow: handwritten and obfuscated code jumps into the middle of loops, so a backward walk from a back-edge escapes past the header and swallows unrelated blocks; bail out when the walk reaches a block that precedes the header
- Ownership confusion: same pointer freed on two paths, or freed by callee and caller
- Integer overflow on
size * countbefore allocation
radare2 quick commands
aaa # analyze all
pdf # disassemble function
afvd # show variables and arguments
VV # visual graph
axt # find xrefs to symbol
db / dc # breakpoint / continue
dr / px # registers / memory
Output
Write findings to a report file (default: ailogic-report.md) so the user can iterate on it while fixing. If the file exists, append new findings under a fresh dated section instead of overwriting; mark resolved entries with ✅ rather than deleting them, so progress is visible across runs.
Report structure
# ailogic r
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ailogic?
Find logic bugs in C code for radare2 by analyzing control flow, state transitions, and silent assumptions.
Как установить скилл ailogic?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ailogic запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…