Skip to content

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

Closed

Description

@bradfitz
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)
}

Activity

  1. rsc commented on Jul 13, 2010

    @rsc
    Contributor

    Comment 1:

    codereview.appspot.com/1812043

    Owner changed to r...@golang.org.

    Status changed to Started.

  2. peterGo commented on Jul 13, 2010

    @peterGo
    Contributor

    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.
  3. bradfitz commented on Jul 13, 2010

    @bradfitz
    ContributorAuthor

    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)
                    }
            }
  4. peterGo commented on Jul 13, 2010

    @peterGo
    Contributor
  5. bradfitz commented on Jul 13, 2010

    @bradfitz
    ContributorAuthor
  6. robpike commented on Jul 14, 2010

    @robpike
    Contributor

    Comment 6:

    Status changed to Fixed.

  7. locked and limited conversation to collaborators on Jun 24, 2016
  8. removed their assignment
    on Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions