Skip to content

Security: Replace unsafe string functions (strcpy/strcat/sprintf) #7

@montge

Description

@montge

Summary

Replace unsafe string functions with bounds-checked alternatives throughout the codebase.

Affected Files

  • spinlex.c - Multiple strcpy/strcat calls (lines 209, 227, 551, 700, 701, 1095, 1149, 1200, 1236, 1324, 1329, 1841, 1976, 1981, 1986, 1990, 2016)
  • structs.c - sprintf/strcat on stack buffers (lines 385, 400, 404, 405, 407, 408, 467, 471, 472, 475, 476, 493, 495, 501, 502, 503)
  • main.c - sprintf with offset accumulation (lines 296-314)
  • pangen3.c - strncpy without null termination check (line 449)
  • tl_mem.c - strncpy issues (line 91)

Required Changes

  1. Replace strcpy() with snprintf() or bounds-checked copy
  2. Replace strcat() with snprintf() or strncat() with proper length
  3. Replace sprintf() with snprintf() and check return values
  4. Ensure all strncpy() results are null-terminated

Testing

  • Run make test after each file is updated
  • Verify no regressions in example verification

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions