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

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

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

Comments

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Feb 27, 2014

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

@bradfitz bradfitz commented Feb 27, 2014

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

@bradfitz bradfitz commented Feb 27, 2014

Comment 2:

This issue was closed by revision 0399b97.

Status changed to Fixed.

@remyoudompheng
Copy link
Contributor

@remyoudompheng remyoudompheng commented Feb 28, 2014

Comment 3:

For issue #7354 I propose to read it.
@bradfitz
Copy link
Contributor Author

@bradfitz bradfitz commented Feb 28, 2014

Comment 4:

That's even better.
@bradfitz bradfitz added fixed labels Feb 28, 2014
@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3maybe label 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.