Skip to content

Commit 2f824cf

Browse files
anandgupta42claude
andcommitted
fix(analyst): refuse the PostgreSQL statistics-reset functions in read-only sql_check sources
`pg_stat_reset`, `pg_stat_reset_shared` and the other `pg_stat_reset*` functions clear cumulative counters that a read-only transaction and rollback cannot restore; they are now part of the denied control-function class. Tests: the three forms rejected before execution. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 4a7c61e commit 2f824cf

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/tools/sql-check.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function readSql(sql: string, dialect?: string): string {
187187
body,
188188
) ||
189189
/\bREPLACE\b(?!\s*\()/i.test(body) ||
190-
/\b(nextval|setval|set_config|load_extension|writefile|dblink\w*|lo_import|lo_export|lo_create|lo_unlink|lo_put|pg_write_file|pg_append_file|pg_file_write|pg_file_rename|pg_file_unlink|pg_(?:try_)?advisory_\w*|pg_(?:wal_replay_\w*|logical_\w*|switch_wal|switch_xlog|create_restore_point|(?:start|stop)_backup|backup_(?:start|stop)|\w*replication\w*|terminate_backend|cancel_backend|promote|reload_conf|rotate_logfile|log_backend_memory_contexts))\s*\(/i.test(
190+
/\b(nextval|setval|set_config|load_extension|writefile|dblink\w*|lo_import|lo_export|lo_create|lo_unlink|lo_put|pg_write_file|pg_append_file|pg_file_write|pg_file_rename|pg_file_unlink|pg_(?:try_)?advisory_\w*|pg_(?:stat_reset\w*|wal_replay_\w*|logical_\w*|switch_wal|switch_xlog|create_restore_point|(?:start|stop)_backup|backup_(?:start|stop)|\w*replication\w*|terminate_backend|cancel_backend|promote|reload_conf|rotate_logfile|log_backend_memory_contexts))\s*\(/i.test(
191191
functions,
192192
)
193193
) {

‎packages/opencode/test/altimate/sql-check-postgres.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ describe("predicate_effect with mocked Postgres", () => {
147147
"pg_sync_replication_slots()",
148148
"pg_replication_origin_create('origin')",
149149
"pg_replication_slot_advance('slot', '0/1')",
150+
"pg_stat_reset()",
151+
"PG_STAT_RESET_SHARED('bgwriter')",
152+
'pg_catalog."pg_stat_reset_single_table_counters" /* reset */ (1)',
150153
],
151154
],
152155
] satisfies [string, string[]][]) {

0 commit comments

Comments
 (0)