Skip to content

Commit

Permalink
unix: convert major/minor to uint64 before shifting in Mkdev on Darwi…
Browse files Browse the repository at this point in the history
…n/*BSD

Follow CL 63090 and change the Makedev function on Darwin and *BSD to
convert to uint64 before shifting/masking. This avoids a potential
overflow.

Change-Id: I5b566329695cc5edcf82f0ff2366033011b0625b
Reviewed-on: https://go-review.googlesource.com/63112
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
tklauser authored and ianlancetaylor committed Sep 12, 2017
1 parent 7a85bfa commit 804a9fe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion unix/dev_darwin.go
Expand Up @@ -20,5 +20,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a Darwin device number generated from the given major and minor
// components.
func Mkdev(major, minor uint32) uint64 {
return uint64((major << 24) | minor)
return (uint64(major) << 24) | uint64(minor)
}
2 changes: 1 addition & 1 deletion unix/dev_dragonfly.go
Expand Up @@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a DragonFlyBSD device number generated from the given major and
// minor components.
func Mkdev(major, minor uint32) uint64 {
return uint64((major << 8) | minor)
return (uint64(major) << 8) | uint64(minor)
}
2 changes: 1 addition & 1 deletion unix/dev_freebsd.go
Expand Up @@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a FreeBSD device number generated from the given major and
// minor components.
func Mkdev(major, minor uint32) uint64 {
return uint64((major << 8) | minor)
return (uint64(major) << 8) | uint64(minor)
}
6 changes: 3 additions & 3 deletions unix/dev_netbsd.go
Expand Up @@ -22,8 +22,8 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a NetBSD device number generated from the given major and minor
// components.
func Mkdev(major, minor uint32) uint64 {
dev := uint64((major << 8) & 0x000fff00)
dev |= uint64((minor << 12) & 0xfff00000)
dev |= uint64((minor << 0) & 0x000000ff)
dev := (uint64(major) << 8) & 0x000fff00
dev |= (uint64(minor) << 12) & 0xfff00000
dev |= (uint64(minor) << 0) & 0x000000ff
return dev
}

0 comments on commit 804a9fe

Please sign in to comment.