Skip to content

windows: fix readlink buffer size issue#2153

Merged
BareosBot merged 8 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-win-symlink-handling
Feb 10, 2025
Merged

windows: fix readlink buffer size issue#2153
BareosBot merged 8 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-win-symlink-handling

Conversation

@sebsura
Copy link
Contributor

@sebsura sebsura commented Feb 6, 2025

When encountering a symlink on windows, we try to discover the real path by allocating a fixed size buffer and handing it to windows.

The problem is that this buffer may not be big enough! If the buffer is too small, then the function will just outright fail, but if the buffer is just big enough, then the client may crash as we try to write some bytes past the end of the section that windows just wrote, i.e. outside the allocated buffer in this case.

This PR also includes a fix for our grpc test module. The module did not create the connection in the right order leading to failed tests.

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

This if does not make sense here
We allocated too little memory to hold the information we wanted to
have.  We reserved 544 bytes total, which left 524 bytes for the
PathBuffer.  This buffer contains two paths: The print name and the
substitute name.  Each can (probably) contain up to 260*2 bytes,
e.g. 1040 bytes total.

This means that the function would fail for very long strings and
would crash for certain strings as we try to write to one-past the
path (which would be ok if we made sure to allocate enough space!)

On our cd/ci infrastructure, we hit exactly that issue:  The
PathBuffer used up _exactly_ all bytes given, leading to the crash!
Copy link
Contributor

@florian-at-bareos florian-at-bareos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good, thanks for your work!

We should make sure to only accept requests from the client once the
global state (con) is completely setup, otherwise we risk deferencing
an invalid optional.
@BareosBot BareosBot merged commit 36a26c0 into bareos:master Feb 10, 2025
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants