Repository navigation
Bound the Wayland info buffer writes and free the returned info strings - #62
Merged
Merged
Conversation
WaylandInfoString appended to the fixed 10240 byte buf with sprintf(buf + strlen(buf), ...), so output longer than the buffer was written past its end. Let BUF also pass the space left in buf, and use snprintf for every append, so output that does not fit is truncated. X11InfoString and WaylandInfoString return a calloc'ed copy of the info text, which XInfo and WaylandInfo never freed. Free it after copying it into a Go string. Fixes xyproto#59 Fixes xyproto#60 Fixes xyproto#61
Owner
|
Thanks for the PR, merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
include/wayinfo.h (#59):
BUFnow expands tobuf + strlen(buf), sizeof(buf) - strlen(buf), and all 20sprintf(BUF, ...)calls are nowsnprintf(BUF, ...). Every append is limited to the space left inbuf; output that does not fit is truncated instead of being written past the end of the 10240 byte buffer. The output for anything that fits is unchanged.xinfo.go (#60), wayinfo.go (#61):
X11InfoString()/WaylandInfoString()return acalloc'ed copy of the info text and clear the static buffer, so the caller owns the returned pointer.XInfo()andWaylandInfo()now keep the pointer, copy it withC.GoStringandC.freeit (deferred). Both headers already include<stdlib.h>.C.free(NULL)andC.GoString(nil)are both safe, so a NULL return still produces an empty string as before.Testing
Run in a
golang:1.27(Debian, arm64) container withlibx11-dev libxcursor-dev libxmu-dev libwayland-dev libxpm-dev xbitmaps libxmu-headers libheif-dev(the CI package list), plusXvfb :99 -noresetwith two screens andweston --backend=headless:makesucceeds andgo vet .passes, before and after.go test -count=10 -mod=vendor -run 'TestXMonitors|TestWaylandMonitors' -v .: 10/10 passes for each test, before and after. Both return the same monitors as before.-fsanitize=addressthat includesinclude/wayinfo.hand passessprint_infos()100 registry entries with 200 character interface names:AddressSanitizer: global-buffer-overflow ... WRITE of size 237invsprintfstrlen(buf) = 10239, sizeof(buf) = 10240mallinfo2().uordblks):XInfo()(281 byte result)WaylandInfo()(1339 byte result)The remaining growth in
WaylandInfo()comes from the per-call registry/output records inwayinfo.h. This PR does not change them.Fixes #59
Fixes #60
Fixes #61