-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Ignore argc when setting up CommandLine.arguments #74739
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
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test Windows |
[stdlib] Ignore argc when setting up CommandLine.arguments
Wait, is |
@grynspan not the Swift interface, the actual underlying argc and argv (at least on Darwin) |
Oh, right, the underlying pointer isn't owned by Swift. I wonder if we should change that given the inherent concurrency unsafety of it, or perhaps offer a |
C99 §5.1.2.2.1 ¶2:
One thing it doesn't mention is that a traditional use of this on UNIX is the ability to change what |
That's required for C, but I'm talking about Swift API. We can do better! |
True, though we need to bear in mind what the underlying situation is, which is why I mention it. Particularly if we're going to try to lazily capture the argument vector, the fact that C code is free to randomly overwrite it as it sees fit is problematic. |
I think the crux of what I'm saying is that our API surface should be as reliable as is practical. I don't know if we can do much about somebody smashing But, assuming that modifying |
Unfortunately argc and argv are globally accessible and mutable so in some cases these values may be out of sync with each other. This can result in a crash when accessing
CommandLine.arguments
because if someone stomps on argv and inserts a null within0 ..< argc
but doesn't update argc, we will attempt to read0 ..< argc
number of strings and crash when trying to unwrap one of the c string pointers in the argv array. Lets just ignore argc and manually iterate argv to find argc for ourselves.Resolves: rdar://130346225 and rdar://129708138