apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.96k stars 648 forks source link

IPv6 Address description contains 0-bytes #110

Closed helje5 closed 6 years ago

helje5 commented 6 years ago

Expected behavior

No 0 bytes in strings

Actual behavior

0 bytes in strings

Steps to reproduce

In Xcode:

  1. after a server bootstrap, doprint("Server running on:", serverChannel.localAddress!)
  2. copy output to e.g. TextMate

It says: Server running on: [IPv6]::1<NUL><NUL><NUL>....lots...

Some editors seem to eat the \0's.

Cause

I think it is

private func descriptionForAddress(family: CInt, bytes: UnsafeRawPointer, length byteCount: Int) -> String {
...
            return String(decoding: UnsafeBufferPointer<UInt8>(start: addressBytesPtr, count: byteCount), as: Unicode.ASCII.self)

That leaves the 0's from the address buffer in the String. I think you probably want some

return String(cString: addressBytesPtr)

variant here, so that the string terminates at the \0.

Other potential causes: incorrect indentation, 80-column source line length overflows all over.

SwiftNIO version/commit hash

1.1

Swift & OS version (output of swift --version && uname -a)

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2) Target: x86_64-apple-macosx10.9 Darwin ZeaPro.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64

Lukasa commented 6 years ago

Agreed, this looks wrong. Are you open to filing a patch to fix that?

helje5 commented 6 years ago

Sure, why not. I'll send a PR later this evening.

normanmaurer commented 6 years ago

@helje5 thanks!

normanmaurer commented 6 years ago

Fixed by https://github.com/apple/swift-nio/pull/111