Skip to content
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

syscall: why doesn't Accept4 read from accept4's *len result parameter? #7428

Closed
bradfitz opened this issue Feb 27, 2014 · 4 comments
Closed
Milestone

Comments

@bradfitz
Copy link
Contributor

Question from Rob:

The accept4 system call has a in+out socklen_t *addrlen parameter.

In syscall_linux.go, we use it as an in parameter, but never read the result:

func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
        var rsa RawSockaddrAny
        var len _Socklen = SizeofSockaddrAny
        nfd, err = accept4(fd, &rsa, &len, flags)
        if err != nil {
                return
        }
        sa, err = anyToSockaddr(&rsa)
        if err != nil {
                Close(nfd)
                nfd = 0
        }
        return
}


Likewise in Darwin (https://golang.org/cl/68880043/).

Should we?

Or is func anyToSockaddr safe as-is?  Why?
@bradfitz
Copy link
Contributor Author

Comment 1:

Oh, because types_$GOOS.go defines a union struct:
union sockaddr_all {                                                                    
                                       
        struct sockaddr s1;     // this one gets used for fields                                                                
        struct sockaddr_in s2;  // these pad it out                                                                             
        struct sockaddr_in6 s3;                                                                                                 
        struct sockaddr_un s4;                                                                                                  
        struct sockaddr_dl s5;                                                                                                  
};                                                                                      
                                       
                                                                                                                                
struct sockaddr_any {                                                                   
                                       
        struct sockaddr addr;                                                                                                   
        char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];                                                         
};                                                                                      
                                       
And the SizeofSockaddrAny is SizeofSockaddrAny = C.sizeof_struct_sockaddr_any, the
maximum size of any address we can accept.

@bradfitz
Copy link
Contributor Author

Comment 2:

This issue was closed by revision 0399b97.

Status changed to Fixed.

@remyoudompheng
Copy link
Contributor

Comment 3:

For issue #7354 I propose to read it.

@bradfitz
Copy link
Contributor Author

Comment 4:

That's even better.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants