-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
String.cstring() fails to null-terminate a trimmed string under certain circumstances. #2613
Comments
Here is a snippet of an lldb session which reveals what happens in
|
It looks like this is a simple off-by-one issue, which only affects cases where the memory location being returned from alloc has already been used. it should be |
mfelsche
added
complexity: beginner friendly
and removed
bug: 1 - needs investigation
labels
Mar 28, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bug happened to me, when extracting the port from a command line arg like
localhost:9999:A
usingString.trim
and passing this toTCPListener.create
. It failed to start listening, turned out the port/service cstring which should have been9999
, which was a shared slice of the wholelocalhost:9999:A
, was actually:9999:A
, becauseString.cstring()
failed to null-terminate thechar*
properly.This happened to me on both of these systems, both compiling in debug and release mode:
Linux 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Linux 4.14.24 #1-NixOS SMP Sat Mar 3 09:24:39 UTC 2018 x86_64 GNU/Linux
Code to reproduce: https://gist.github.com/mfelsche/6b377d9aa83eb45c1307a5ecec37447f
If it prints
.
everything is fine, if it prints andE
, the string was not properly null-terminated.I was not able to reproduce this in any other way. The traces of the string in question come from a cloned
Array[String]
that isshift()?
ed until nothing is left. The string is then trimmed to cut out the part between the colons. Nothing super-special. Puzzling.The text was updated successfully, but these errors were encountered: