Skip to content

macOS: check for nil before copying clipboard text in and out - #102

Closed
andr0s wants to merge 1 commit into
dacap:mainfrom
andr0s:macos-utf8-checks
Closed

andr0s wants to merge 1 commit into
dacap:mainfrom
andr0s:macos-utf8-checks

Conversation

@andr0s

@andr0s andr0s commented Oct 19, 2026

Copy link
Copy Markdown

Fixes #101.

Two checks in the text paths of clip_osx.mm:

  • get_data: return false when [string UTF8String] is NULL instead of passing it to memcpy. string is nil when the pasteboard no longer holds text by the time stringForType: runs, and reqsize is still 1 then (0 + 1); UTF8String is also declared nullable.
  • set_data: return false when the bytes are not valid UTF-8. initWithBytesNoCopy:length:encoding: returns nil then, and setString:nil forType: still returns YES, so set_text reported success without copying anything.

Builds in Codeware's macOS port (Apple clang, arm64). Both nil cases were checked with a small program against a private pasteboard (pasteboardWithUniqueName) on macOS 26.5.

I agree that my contributions are licensed under the MIT License.
You can find a copy of this license at https://opensource.org/licenses/MIT

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dacap

dacap commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Sorry I cannot accept patches generated or co-authored with generative AI. I'll update the PR guidelines.

@dacap dacap closed this Oct 19, 2026
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.

macOS: get_data can memcpy from NULL; set_data reports success for invalid UTF-8

2 participants