Skip to content

Harden protocol input validation and numeric parsing #72

@AlexJuca

Description

@AlexJuca

Context

Several command handlers parse protocol fields and numeric values directly from client-controlled input. Production readiness requires strict validation with clear failure behavior, especially for TTLs, integer commands, length fields, and malformed frames.

Examples to review:

  • src/commands/server/server_command_handlers.c: SET EX and EXPIRE use strtoll() without checking endptr, overflow, negative values, or trailing junk.
  • Command handlers often trust key_len, value_len, and optional payload layouts independently.
  • Integer command parsing should consistently reject invalid values and detect overflow/underflow.

Scope

  • Add shared helpers for safe unsigned/signed integer parsing.
  • Validate complete consumption of numeric input (endptr), range, sign rules, and overflow/underflow.
  • Define expected behavior for invalid TTL values: reject non-numeric, negative, overflowing, and truncated values.
  • Centralize protocol frame validation where possible so handlers are less error-prone.
  • Add malformed-frame tests for every command family.

Acceptance criteria

  • Invalid TTLs and integer values return framed errors, not silently coerced values.
  • Overflow/underflow is detected for INCR, INCRBY, DECR, and DECRBY.
  • Length-field inconsistencies cannot read outside the received frame.
  • Tests cover invalid numeric values, truncated frames, oversized advertised lengths, extra bytes, and zero-length keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritysecurity issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions