Skip to content

fix: prevent signed/unsigned mix in TcpConn::isend#116

Open
VecherVhatuX wants to merge 2 commits intoyedf2:masterfrom
VecherVhatuX:prevent_signed_unsigned_mix
Open

fix: prevent signed/unsigned mix in TcpConn::isend#116
VecherVhatuX wants to merge 2 commits intoyedf2:masterfrom
VecherVhatuX:prevent_signed_unsigned_mix

Conversation

@VecherVhatuX
Copy link
Copy Markdown

In TcpConn::isend, the variable sended is size_t (unsigned), while wd returned from writeImp is ssize_t (signed). The original code sended += wd; mixes signed and unsigned types. If wd is negative (e.g., -1 on error), adding it to sended would convert it to a large positive value, potentially causing wraparound or logic errors.

This is a classic case of CWE-190: Integer Overflow or Wraparound
(https://cwe.mitre.org/data/definitions/190.html).

Fix:

  • Only add wd to sended when wd > 0
  • Ensures that no signed value is implicitly converted to unsigned
  • Keeps original logic intact for normal write operations

Importance:

  • Prevents accidental large values for sended
  • Ensures correct accounting of bytes sent
  • Avoids potential memory or buffer misuse

@ggandycong
Copy link
Copy Markdown

ggandycong commented Sep 5, 2025 via email

@VecherVhatuX
Copy link
Copy Markdown
Author

@ggandycong, could you please tell whether this PR is ok or should we just close the PR?

@ggandycong
Copy link
Copy Markdown

ggandycong commented Nov 14, 2025 via email

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.

2 participants