Skip to content

Improve robustness of readlink uses - #2873

Closed
smcv wants to merge 2 commits into
flatpak:masterfrom
smcv:readlinkat
Closed

smcv wants to merge 2 commits into
flatpak:masterfrom
smcv:readlinkat

Conversation

@smcv

@smcv smcv commented May 1, 2019

Copy link
Copy Markdown
Collaborator

readlink() and readlinkat() have weird semantics: they return the number of bytes they would have written if there was enough space, even if that's larger than the buffer. Flatpak didn't always cope with this, and it looks as though it might write \0 outside the buffer if a symlink target is longer than PATH_MAX.

glnx_readlinkat_malloc() takes care to do the right thing in all situations, so use that where possible.

In the icon validator and the portal, which don't currently use libglnx, treat an excessively long symlink target as an error instead.

smcv added 2 commits April 30, 2019 18:25
If the buffer is too small, readlink() returns the number of bytes that
would have been stored if the buffer had been large enough.

Signed-off-by: Simon McVittie <[email protected]>
readlink() and readlinkat() have weird semantics (they return the
number of bytes they would have written if there was enough space,
even if that's larger than the buffer), but glnx_readlinkat_malloc()
takes care to do the right thing in all situations.

Signed-off-by: Simon McVittie <[email protected]>
@matthiasclasen

Copy link
Copy Markdown
Collaborator

@rh-atomic-bot r+

@rh-atomic-bot

Copy link
Copy Markdown

📌 Commit 8d1c3c6 has been approved by matthiasclasen

@rh-atomic-bot

Copy link
Copy Markdown

⚡ Test exempted: pull fully rebased and already tested.

rh-atomic-bot pushed a commit that referenced this pull request May 1, 2019
readlink() and readlinkat() have weird semantics (they return the
number of bytes they would have written if there was enough space,
even if that's larger than the buffer), but glnx_readlinkat_malloc()
takes care to do the right thing in all situations.

Signed-off-by: Simon McVittie <[email protected]>

Closes: #2873
Approved by: matthiasclasen
alexlarsson pushed a commit to alexlarsson/flatpak that referenced this pull request Sep 19, 2019
If the buffer is too small, readlink() returns the number of bytes that
would have been stored if the buffer had been large enough.

Signed-off-by: Simon McVittie <[email protected]>

Closes: flatpak#2873
Approved by: matthiasclasen

(cherry picked from commit 89dc344)
rh-atomic-bot pushed a commit that referenced this pull request Sep 19, 2019
If the buffer is too small, readlink() returns the number of bytes that
would have been stored if the buffer had been large enough.

Signed-off-by: Simon McVittie <[email protected]>

Closes: #2873
Approved by: matthiasclasen

(cherry picked from commit 89dc344)

Closes: #3115
Approved by: alexlarsson
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.

3 participants