Skip to content

bugfixes#33

Merged
csd113 merged 1 commit intomainfrom
indev
Mar 18, 2026
Merged

bugfixes#33
csd113 merged 1 commit intomainfrom
indev

Conversation

@csd113
Copy link
Owner

@csd113 csd113 commented Mar 18, 2026

Fix: backup validation, logging rotation, and DB consistency improvements

This PR completes updates to backup.rs and logging.rs, along with several fixes across the database layer.


Summary of Changes

db/posts.rs

  • Add custom theme linker #13 – Constant-time comparison

    • Replaced custom constant_time_eq with subtle::ConstantTimeEq
    • Use: a.ct_eq(b).into()
    • Added import: use subtle::ConstantTimeEq as _
    • Removed hand-rolled implementation
  • Pruned dead code, bumped version, fixed typos #16 – Poll vote race condition

    • Updated cast_vote query:
      • JOINs polls table
      • Adds expiry guard: sql AND (p.expires_at IS NULL OR p.expires_at > unixepoch())
    • Prevents race between handler validation and INSERT
  • Proper error logging output #25edit_window_secs semantics

    • 0 → no time limit (skips check via Option)
    • Negative → fallback to 300s
    • Positive → used as-is

handlers/admin/backup.rs

  • update readme for 1.0.13 #19 – SQLite validation

    • Added magic byte check (b"SQLite format 3\0") after extracting chan.db
    • Applied to:
      • admin_restore
      • restore_saved_board_backup
    • Invalid DB now returns 400 Bad Request before rusqlite usage
  • Alpha v1.1.0dev3 api hooks #30 – Duplicate encoding logic removed

    • Removed inner encode_q / nibble definitions
    • Introduced single module-level encode_q
    • Shared across:
      • admin_restore
      • restore_saved_board_backup
      • board_restore

db/logging.rs (moved from logging.rs)

  • bugfixes #33 – Log rotation

    • Replaced rolling::never with rolling::daily
    • Logs now rotate automatically: rustchan.log.YYYY-MM-DD
  • Location + API updates

    • Moved file to: db/logging.rs
    • Renamed log_dirdb_dir
    • Logs now stored alongside chan.db
    • Updated documentation accordingly

Required Follow-ups

  • Update module declaration:

## Fix: backup validation, logging rotation, and DB consistency improvements

This PR completes updates to `backup.rs` and `logging.rs`, along with several fixes across the database layer.

---

### Summary of Changes

#### `db/posts.rs`

- **#13 – Constant-time comparison**
  - Replaced custom `constant_time_eq` with `subtle::ConstantTimeEq`
  - Use: `a.ct_eq(b).into()`
  - Added import: `use subtle::ConstantTimeEq as _`
  - Removed hand-rolled implementation

- **#16 – Poll vote race condition**
  - Updated `cast_vote` query:
    - JOINs `polls` table
    - Adds expiry guard:
      ```sql
      AND (p.expires_at IS NULL OR p.expires_at > unixepoch())
      ```
  - Prevents race between handler validation and INSERT

- **#25 – `edit_window_secs` semantics**
  - `0` → no time limit (skips check via `Option`)
  - Negative → fallback to 300s
  - Positive → used as-is

---

#### `handlers/admin/backup.rs`

- **#19 – SQLite validation**
  - Added magic byte check (`b"SQLite format 3\0"`) after extracting `chan.db`
  - Applied to:
    - `admin_restore`
    - `restore_saved_board_backup`
  - Invalid DB now returns `400 Bad Request` before `rusqlite` usage

- **#30 – Duplicate encoding logic removed**
  - Removed inner `encode_q` / `nibble` definitions
  - Introduced single module-level `encode_q`
  - Shared across:
    - `admin_restore`
    - `restore_saved_board_backup`
    - `board_restore`

---

#### `db/logging.rs` (moved from `logging.rs`)

- **#33 – Log rotation**
  - Replaced `rolling::never` with `rolling::daily`
  - Logs now rotate automatically:
    ```
    rustchan.log.YYYY-MM-DD
    ```

- **Location + API updates**
  - Moved file to: `db/logging.rs`
  - Renamed `log_dir` → `db_dir`
  - Logs now stored alongside `chan.db`
  - Updated documentation accordingly

---

### Required Follow-ups

- Update module declaration:

  ```rust
  // db/mod.rs
  pub mod logging;
@csd113 csd113 merged commit 31b1615 into main Mar 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant