Skip to content

fix: Off-by-one buffer errors in ircd_snprintf and ircd_strncpy calls#85

Open
MrLenin wants to merge 1 commit intoevilnet:masterfrom
MrLenin:fix/off-by-one-buffers
Open

fix: Off-by-one buffer errors in ircd_snprintf and ircd_strncpy calls#85
MrLenin wants to merge 1 commit intoevilnet:masterfrom
MrLenin:fix/off-by-one-buffers

Conversation

@MrLenin
Copy link
Contributor

@MrLenin MrLenin commented Feb 6, 2026

Summary

  • Fix off-by-one errors where buffers declared as [SIZE+1] were passed to ircd_snprintf or ircd_strncpy with SIZE instead of SIZE+1
  • ircd_snprintf(0, buf, n, ...) writes at most n-1 characters plus null terminator
  • ircd_strncpy(dest, src, n) copies n-1 characters plus null terminator
  • Using SIZE instead of SIZE+1 truncates the last valid character

Files Changed

  • channel.c: tmphost[HOSTLEN+1] buffer in add_banid() - fix snprintf size
  • m_userip.c: iphost[HOSTLEN+1] buffer - fix 5 snprintf calls
  • s_user.c:
    • newhost[HOSTLEN+1] buffer in hide_hostmask() - fix 2 snprintf calls
    • Account parsing with timestamped accounts (e.g., user:1234567890) - fix ircd_strncpy length calculation

Test plan

  • Verify hosts at exactly HOSTLEN (63 chars) are not truncated
  • Verify account names at exactly ACCOUNTLEN (15 chars) with timestamps parse correctly

🤖 Generated with Claude Code

ircd_snprintf(buf, size, ...) writes at most size-1 characters plus null.
ircd_strncpy(dest, src, len) copies len-1 characters plus null.

When a buffer is declared as buf[SIZE+1] to hold SIZE characters plus
the null terminator, the copy function must be called with SIZE+1 as
the length parameter, not SIZE.

Fixed locations:
- channel.c: find_ban() tmphost buffer for hidden host matching
- m_userip.c: userip_formatter() iphost buffer (5 instances)
- s_user.c: hide_hostmask() newhost buffer for account-based hiding
- s_user.c: set_user_mode() account parsing with timestamped accounts

The account parsing bug caused usernames like "ibutsu:1234567890" to be
truncated to "ibuts" when received via P10 NICK burst with timestamp.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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