llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[libc] Improve wcslcat and wcsncat implementation.

Open vonosmas opened this issue 5 months ago • 4 comments

Today the implementation of wcslcat https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcslcat.cpp#L22-L24 is problematic:

  • it effectively calls unbounded wcslen on destination string (the length might be larger than dstsize)
  • computing dstsize-dstlen-1 in size_t type might also underflow (though subsequent cast to int would result in positive integer in extremely rare circumstances)

wcsncat implementation: https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcsncat.cpp#L23-L25

also has on OOB read of character at position n in s2.

vonosmas avatar Jun 12 '26 22:06 vonosmas

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvm/issue-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Today the implementation of `wcslcat` https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcslcat.cpp#L22-L24 is problematic: * it effectively calls unbounded wcslen on destination string (the length might be larger than `dstsize`) * computing `dstsize-dstlen-1` in size_t type might also underflow (though subsequent cast to int would result in positive integer in extremely rare circumstances)

wcsncat implementation: https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcsncat.cpp#L23-L25

also has on OOB read of character at position n in s2.

@llvm/issue-subscribers-good-first-issue

Author: Alexey Samsonov (vonosmas)

Today the implementation of `wcslcat` https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcslcat.cpp#L22-L24 is problematic: * it effectively calls unbounded wcslen on destination string (the length might be larger than `dstsize`) * computing `dstsize-dstlen-1` in size_t type might also underflow (though subsequent cast to int would result in positive integer in extremely rare circumstances)

wcsncat implementation: https://github.com/llvm/llvm-project/blob/c9b25a6437fd97fdb1e55ab6661c0cccce98913e/libc/src/wchar/wcsncat.cpp#L23-L25

also has on OOB read of character at position n in s2.

Hii, I would like to work on this issue

hardikxk avatar Jun 13 '26 04:06 hardikxk