Skip to content

missing unlock in crypt/rand/rand_unix.go #917

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

Closed
bradfitz opened this issue Jul 13, 2010 · 6 comments
Closed

missing unlock in crypt/rand/rand_unix.go #917

bradfitz opened this issue Jul 13, 2010 · 6 comments

Comments

@bradfitz
Copy link
Contributor

Just noticed on ,

http://code.google.com/p/go/source/browse/src/pkg/crypto/rand/rand_unix.go?spec=svn42e4767b10beb7eeb7a3c7db372279e8c01b45c3&;r=42e4767b10beb7eeb7a3c7db372279e8c01b45c3


func (r *devReader) Read(b []byte) (n int, err os.Error) {
    r.mu.Lock()
    if r.f == nil {
        f, err := os.Open(r.name, os.O_RDONLY, 0)
        if f == nil {
>>>>>>>>>>>>>>>>>>>>>>>
/// MISSING m.mu.Unlock()
            return 0, err
        }
        r.f = f
    }
    r.mu.Unlock()
    return r.f.Read(b)
}
@rsc
Copy link
Contributor

rsc commented Jul 13, 2010

Comment 1:

codereview.appspot.com/1812043

Owner changed to [email protected].

Status changed to Started.

@peterGo
Copy link
Contributor

peterGo commented Jul 13, 2010

Comment 2:

By design, all versions of crypto/rand minimize differences, and use the same or similar
patterns wherever possible. Therefore, if it's wrong in Unix, it's probably wrong in
Windows too. And it is.

@bradfitz
Copy link
Contributor Author

Comment 3:

$ hg diff pkg/crypto/rand/rand_windows.go
diff -r 4f91458c5765 src/pkg/crypto/rand/rand_windows.go
--- a/src/pkg/crypto/rand/rand_windows.go       Tue Jul 13 10:47:52 2010 +1000
+++ b/src/pkg/crypto/rand/rand_windows.go       Tue Jul 13 11:09:52 2010 -0700
@@ -30,6 +30,7 @@
                const flags = syscall.CRYPT_VERIFYCONTEXT | syscall.CRYPT_SILENT
                ok, errno := syscall.CryptAcquireContext(&r.prov, nil, nil, provType, flags)
                if !ok {
+                       r.mu.Unlock()
                        return 0, os.NewSyscallError("CryptAcquireContext", errno)
                }
        }

@peterGo
Copy link
Contributor

peterGo commented Jul 13, 2010

Comment 4:

http://golang.org/cl/1764044

@bradfitz
Copy link
Contributor Author

@robpike
Copy link
Contributor

robpike commented Jul 14, 2010

Comment 6:

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
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

5 participants