-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix empty token on swift package-registry login (Issue #7453) #7454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix empty token on swift package-registry login (Issue #7453) #7454
Conversation
the allocated buffer is not valid anymore after reading in the access token from the command line. `withUnsafeMutableBuffer` unfortunately doesn't work since readpassphrase internally seems to move the buffer which leads to a runtime exception.
Hi @pwallrich, thank you for the contribution? Would you be able to add a test for this to our test suite to prevent possible regressions in the future? |
Hey @MaxDesiatov. Could be quite hard, since it only happens in release builds. But I'll try to find a way to trigger it reliably in tests. Do you know if there already exist tests for things like that so I wouldn't have to reinvent the wheel? |
Ok I've managed to write a test for it, but it's actually a bit nasty since I have to change the stdin. I also had to create a separate testTarget since the test needs to be built with optimisation and therefore can't use @testable. I don't know, how I would add to the CI. The more I think about this bug the more I question whether reverting the change introducing Do you have any thoughts about that? |
@swift-ci test |
swiftlang#7454) Fix empty token when adding a new package-registry and adding token interactively on release builds ### Motivation: When executing swift package-registry login it asks for a token but fails to retrieve it properly. It sends an empty string to the registry server and login therefore fails. (see swiftlang#7453) ### Modifications: I've debugged the code a bit and found out, that somehow `buffer` and `passwordPtr` don't seem to be holding correct values after the `readpassphrase` call. - An easy quick fix is to make sure that `buffer` doesn't get deallocated by adding smth like `_ = buffer` after the String init. This works but is not nice. - My first try was to use `buffer` instead of `passwordPtr` to create the string. These works, but I remember reading somewhere that `&` can be quite nasty sometimes. - I also tried `buffer.withUnsafeMutablePointer`. However `readpassphrase` seems to not only change the content of `buffer` but move it. This leads to a runtime failure `Fatal error: Array withUnsafeMutableBufferPointer: replacing the buffer is not allowed` ### Result: The buffer is retained, the token is properly parsed and sent to the server.
swiftlang#7454) Fix empty token when adding a new package-registry and adding token interactively on release builds ### Motivation: When executing swift package-registry login it asks for a token but fails to retrieve it properly. It sends an empty string to the registry server and login therefore fails. (see swiftlang#7453) ### Modifications: I've debugged the code a bit and found out, that somehow `buffer` and `passwordPtr` don't seem to be holding correct values after the `readpassphrase` call. - An easy quick fix is to make sure that `buffer` doesn't get deallocated by adding smth like `_ = buffer` after the String init. This works but is not nice. - My first try was to use `buffer` instead of `passwordPtr` to create the string. These works, but I remember reading somewhere that `&` can be quite nasty sometimes. - I also tried `buffer.withUnsafeMutablePointer`. However `readpassphrase` seems to not only change the content of `buffer` but move it. This leads to a runtime failure `Fatal error: Array withUnsafeMutableBufferPointer: replacing the buffer is not allowed` ### Result: The buffer is retained, the token is properly parsed and sent to the server.
swiftlang#7454) Fix empty token when adding a new package-registry and adding token interactively on release builds ### Motivation: When executing swift package-registry login it asks for a token but fails to retrieve it properly. It sends an empty string to the registry server and login therefore fails. (see swiftlang#7453) ### Modifications: I've debugged the code a bit and found out, that somehow `buffer` and `passwordPtr` don't seem to be holding correct values after the `readpassphrase` call. - An easy quick fix is to make sure that `buffer` doesn't get deallocated by adding smth like `_ = buffer` after the String init. This works but is not nice. - My first try was to use `buffer` instead of `passwordPtr` to create the string. These works, but I remember reading somewhere that `&` can be quite nasty sometimes. - I also tried `buffer.withUnsafeMutablePointer`. However `readpassphrase` seems to not only change the content of `buffer` but move it. This leads to a runtime failure `Fatal error: Array withUnsafeMutableBufferPointer: replacing the buffer is not allowed` ### Result: The buffer is retained, the token is properly parsed and sent to the server. (cherry picked from commit d8c8d0f)
*Explanation*: I went through the last few months of PRs to make sure anything relevant is cherry-picked. Most of these are NFC but cherry-picking will help with conflicts. The main are: * Better error message - #7419 * Fix for visionOS for `--build-system xcode` - #7448 * Package registry fix - #7454 * Manifest editing API for adding target dependencies - #7552 * Various sendable annotations *Scope*: Package manifests/graphs with duplicate product/target names. *Risk*: Very low *Reviewed By*: Various, mostly @MaxDesiatov --------- Co-authored-by: Max Desiatov <m_desiatov@apple.com> Co-authored-by: k-kohey <kawagutsuchi@gmail.com> Co-authored-by: miharu <35392604+mnaruse@users.noreply.github.com> Co-authored-by: Ryu <87907656+Ryu0118@users.noreply.github.com> Co-authored-by: Philipp Wallrich <p.wallrich@gmail.com> Co-authored-by: Boris Bügling <bbuegling@apple.com> Co-authored-by: coffmark <52638834+coffmark@users.noreply.github.com> Co-authored-by: Doug Gregor <dgregor@apple.com>
Fix empty token when adding a new package-registry and adding token interactively on release builds
Motivation:
When executing swift package-registry login it asks for a token but fails to retrieve it properly. It sends an empty string to the registry server and login therefore fails. (see #7453)
Modifications:
I've debugged the code a bit and found out, that somehow
buffer
andpasswordPtr
don't seem to be holding correct values after thereadpassphrase
call.buffer
doesn't get deallocated by adding smth like_ = buffer
after the String init. This works but is not nice.buffer
instead ofpasswordPtr
to create the string. These works, but I remember reading somewhere that&
can be quite nasty sometimes.buffer.withUnsafeMutablePointer
. Howeverreadpassphrase
seems to not only change the content ofbuffer
but move it. This leads to a runtime failureFatal error: Array withUnsafeMutableBufferPointer: replacing the buffer is not allowed
Result:
The buffer is retained, the token is properly parsed and sent to the server.