greptile: Reduce ruleset to memory-allocation, logging-api, and string-safety#255
greptile: Reduce ruleset to memory-allocation, logging-api, and string-safety#255suphawitwanl wants to merge 1 commit intomasterfrom
Conversation
Adds the slim Greptile review configuration in a single commit so the review bot evaluates the full config end-to-end rather than seeing only incremental diffs. Config snapshot (consolidates work previously landed across PRs #240, #244, #253): - Three C-safety rules: memory-allocation (critical), logging-api (high), string-safety (critical). - logging-api covers flog_err / flog_warn alongside zlog_*. - memory-allocation prefers DEFINE_MTYPE_STATIC for file-local MTYPEs. - commentTypes restricted to documented values (logic/syntax/style). - sequenceDiagramSection explicitly enabled to keep diagrams stable across reviews. - files.json curates supporting doc/ context (workflow, memtypes, logging, lists, cli, etc.). Earlier ~45-rule layout intentionally not restored: P0 topotest / user-docs gates produced false positives on refactor PRs and were removed deliberately. Reference snapshot preserved on the `greptile` branch.
Greptile SummaryThis PR introduces the Greptile review configuration for the FRR repository, adding
|
| Filename | Overview |
|---|---|
| .greptile/config.json | New Greptile configuration with 3 enforcement rules (memory-allocation, logging-api, string-safety); rule texts have minor coverage gaps — strdup/strndup missing from memory-allocation, strncpy/strncat missing from string-safety, fprintf not explicit in logging-api |
| .greptile/files.json | New doc-context manifest pointing at the three canonical FRR developer guides; no issues found |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
PR[Pull Request Opened / Updated] --> G[Greptile triggered\ntriggerOnUpdates: true]
G --> CTX[Load doc context\nworkflow.rst · memtypes.rst · logging.rst]
CTX --> SCOPE{File matches\n**/*.c · **/*.h · **/*.cpp?}
SCOPE -- No --> SKIP[Skip file]
SCOPE -- Yes --> R1[memory-allocation rule\ncritical — P0\nNo malloc/calloc/realloc/free/strdup\nEnforce XMALLOC/XCALLOC/XSTRDUP+MTYPE]
SCOPE -- Yes --> R2[logging-api rule\nhigh — P1\nNo printf/fprintf/stdio\nEnforce zlog_* / flog_err / flog_warn\nDebug guarded by CLI flags]
SCOPE -- Yes --> R3[string-safety rule\ncritical — P0\nNo strcpy/strcat/sprintf/strncpy/strncat\nEnforce strlcpy/strlcat/snprintf+sizeof]
R1 & R2 & R3 --> OUT[Review comment posted\nwith severity + inline suggestion]
OUT --> SC[Status check\npass / fail]
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
.greptile/config.json:32
**`strdup()`/`strndup()` not explicitly forbidden**
The rule forbids `malloc`, `calloc`, `realloc`, and `free`, but `strdup()` and `strndup()` also allocate heap memory outside the MTYPE tracking system and are equally prohibited in FRR — `XSTRDUP(MTYPE_..., s)` is the required replacement. Without naming them here, the rule will silently miss `strdup` calls in PRs. Consider adding them to the "NEVER allow" list alongside `malloc`.
### Issue 2 of 3
.greptile/config.json:44
**`strncpy()` and `strncat()` omitted from the forbidden list**
`strncpy()` does not null-terminate when the source equals or exceeds the destination size, and `strncat()`'s size argument represents remaining space rather than total buffer size — both are classic sources of off-by-one bugs. FRR's coding standards forbid them in favour of `strlcpy()`/`strlcat()`. Listing only `strcpy`, `strcat`, and `sprintf` leaves `strncpy`/`strncat` unguarded by this rule, which could produce false negatives on reviewed PRs.
### Issue 3 of 3
.greptile/config.json:38
**`fprintf()` not explicitly called out**
The rule says "Reject printf() or stdio logging" but `fprintf(stderr, ...)` and `fprintf(stdout, ...)` are the more common real-world offenders in C daemon code that bypass `zlog`. Relying on the implicit "stdio" cover may not be strong enough signal to the AI reviewer — explicitly naming `fprintf` alongside `printf` would close this gap.
Reviews (1): Last reviewed commit: "greptile: add consolidated review config" | Re-trigger Greptile
| "rules": [ | ||
| { | ||
| "id": "memory-allocation", | ||
| "rule": "NEVER allow standard malloc(), calloc(), realloc(), or free(). Enforce FRR's XCALLOC, XMALLOC, XREALLOC, XSTRDUP, and XFREE macros (requires MTYPE). Every allocation must use the MTYPE tracking system declared via DECLARE_MTYPE/DEFINE_MTYPE. Prefer DEFINE_MTYPE_STATIC for module-private types.", |
There was a problem hiding this comment.
strdup()/strndup() not explicitly forbidden
The rule forbids malloc, calloc, realloc, and free, but strdup() and strndup() also allocate heap memory outside the MTYPE tracking system and are equally prohibited in FRR — XSTRDUP(MTYPE_..., s) is the required replacement. Without naming them here, the rule will silently miss strdup calls in PRs. Consider adding them to the "NEVER allow" list alongside malloc.
Prompt To Fix With AI
This is a comment left during a code review.
Path: .greptile/config.json
Line: 32
Comment:
**`strdup()`/`strndup()` not explicitly forbidden**
The rule forbids `malloc`, `calloc`, `realloc`, and `free`, but `strdup()` and `strndup()` also allocate heap memory outside the MTYPE tracking system and are equally prohibited in FRR — `XSTRDUP(MTYPE_..., s)` is the required replacement. Without naming them here, the rule will silently miss `strdup` calls in PRs. Consider adding them to the "NEVER allow" list alongside `malloc`.
How can I resolve this? If you propose a fix, please make it concise.| }, | ||
| { | ||
| "id": "string-safety", | ||
| "rule": "strcpy(), strcat(), and sprintf() are strictly FORBIDDEN — no exceptions, even if the buffer cannot currently overflow (a future change may introduce one). Enforce strlcpy(), strlcat(), and snprintf(). Buffer size arguments MUST use sizeof() wherever possible — never hardcoded size constants.", |
There was a problem hiding this comment.
strncpy() and strncat() omitted from the forbidden list
strncpy() does not null-terminate when the source equals or exceeds the destination size, and strncat()'s size argument represents remaining space rather than total buffer size — both are classic sources of off-by-one bugs. FRR's coding standards forbid them in favour of strlcpy()/strlcat(). Listing only strcpy, strcat, and sprintf leaves strncpy/strncat unguarded by this rule, which could produce false negatives on reviewed PRs.
Prompt To Fix With AI
This is a comment left during a code review.
Path: .greptile/config.json
Line: 44
Comment:
**`strncpy()` and `strncat()` omitted from the forbidden list**
`strncpy()` does not null-terminate when the source equals or exceeds the destination size, and `strncat()`'s size argument represents remaining space rather than total buffer size — both are classic sources of off-by-one bugs. FRR's coding standards forbid them in favour of `strlcpy()`/`strlcat()`. Listing only `strcpy`, `strcat`, and `sprintf` leaves `strncpy`/`strncat` unguarded by this rule, which could produce false negatives on reviewed PRs.
How can I resolve this? If you propose a fix, please make it concise.| }, | ||
| { | ||
| "id": "logging-api", | ||
| "rule": "Reject printf() or stdio logging. Enforce FRR's zlog_* API (zlog_debug, zlog_err, zlog_warn, zlog_info, zlog_notice) and structured error macros flog_err(), flog_warn(), flog_err_sys() (which require an EC_* error-code argument). All debug statements MUST be guarded with CLI-controllable debug flags — unguarded debug prints are unacceptable at scale.", |
There was a problem hiding this comment.
fprintf() not explicitly called out
The rule says "Reject printf() or stdio logging" but fprintf(stderr, ...) and fprintf(stdout, ...) are the more common real-world offenders in C daemon code that bypass zlog. Relying on the implicit "stdio" cover may not be strong enough signal to the AI reviewer — explicitly naming fprintf alongside printf would close this gap.
Prompt To Fix With AI
This is a comment left during a code review.
Path: .greptile/config.json
Line: 38
Comment:
**`fprintf()` not explicitly called out**
The rule says "Reject printf() or stdio logging" but `fprintf(stderr, ...)` and `fprintf(stdout, ...)` are the more common real-world offenders in C daemon code that bypass `zlog`. Relying on the implicit "stdio" cover may not be strong enough signal to the AI reviewer — explicitly naming `fprintf` alongside `printf` would close this gap.
How can I resolve this? If you propose a fix, please make it concise.|
@greptileai I will skipping all three none of them are stated in the loaded docs. |
|
That's not accurate — the docs do cover all three: Memory allocation — Logging —
String safety — The rules are grounded in the loaded documentation. Skipping all three would mean ignoring FRR's documented coding standards.
|
|
To clarify: my comment was about your three suggested additions (
|
|
You're right, and I appreciate the precise citations. My suggested additions overreached what the documentation actually establishes:
My suggestions were inferred intent rather than documented policy. The existing rules are correctly scoped to what the docs actually say, and I shouldn't have proposed extending them without that grounding. Fair correction.
|
Settings:
Rule structure:
Each rule has an id, description, scope, and severity.
Rules cover:
Doc context loaded by Greptile (.greptile/files.json):