-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: Go 2: only give special properties to unsafe.Pointer if package imports unsafe #26070
Comments
Presumably this will also let us redefine |
I like this one. |
Under this proposal, in order to determine whether a conversion expression
(1) and (2) may be arbitrarily distant in the code (even across package boundaries); (3) is fairly easy to find within the source file, but still requires the reader to jump from the current context to the import block and back. In contrast, with a function-based (I do agree that this proposal is a strict improvement over the status quo, but in the space of “fixes for |
I don't find this argument compelling. I think we can safely permit reflect.Value.Pointer to return unsafe.Pointer today anyway (again, Go 1 compatibility rules aside). The Go toolchain no longer supports "safe" mode, so there's no builtin functionality that restricts access to package unsafe. So this argument is implicitly assuming some external safety-validation tool that restricts access to package unsafe. But then I don't see any reason such an external tool can't just look for I think a security-oriented subset of Go a la Joe-E or Caja would be fun to work on, but I don't think trying to one-off tackle individual issues is going to get us there. (I also suspect compiling to wasm is a more pragmatic solution to this problem.) That said, we already tie other unsafe features like So overall I'd say I'm weakly opposed. |
Note that |
@mdempsky's comment does seem like a show-stopper: there's not much point in taking away So probably this proposal should be declined. Now that there are no longer any environments penalizing unsafe (in particular, App Engine does not reject unsafe anymore), we could add reflect.Value.UnsafePointer returning unsafe.Pointer. |
Retracting. |
One of the difficulties of
unsafe.Pointer
is that if a package gets a value of typeunsafe.Pointer
then it can convert that pointer to other pointer types, oruintptr
. This is true even if the package does not itself import "unsafe", but gets theunsafe.Pointer
value by calling some other package. This is the reason thatreflect.Value.Pointer
returnsuintptr
rather thanunsafe.Pointer
.For Go 2 I propose that we change the language to say that values of type
unsafe.Pointer
only have their special properties in packages that explicitly import "unsafe". If a package does not import "unsafe", then a value of typeunsafe.Pointer
may not be converted to other type.If we make that change, then, Go 1 compatibility rules aside, we can safely permit
reflect.Value.Pointer
to returnunsafe.Pointer
.The text was updated successfully, but these errors were encountered: