Commit 804a9fee authored by Tobias Klauser's avatar Tobias Klauser Committed by Ian Lance Taylor

unix: convert major/minor to uint64 before shifting in Mkdev on Darwin/*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/63112Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7a85bfad
...@@ -20,5 +20,5 @@ func Minor(dev uint64) uint32 { ...@@ -20,5 +20,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a Darwin device number generated from the given major and minor // Mkdev returns a Darwin device number generated from the given major and minor
// components. // components.
func Mkdev(major, minor uint32) uint64 { func Mkdev(major, minor uint32) uint64 {
return uint64((major << 24) | minor) return (uint64(major) << 24) | uint64(minor)
} }
...@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 { ...@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a DragonFlyBSD device number generated from the given major and // Mkdev returns a DragonFlyBSD device number generated from the given major and
// minor components. // minor components.
func Mkdev(major, minor uint32) uint64 { func Mkdev(major, minor uint32) uint64 {
return uint64((major << 8) | minor) return (uint64(major) << 8) | uint64(minor)
} }
...@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 { ...@@ -26,5 +26,5 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a FreeBSD device number generated from the given major and // Mkdev returns a FreeBSD device number generated from the given major and
// minor components. // minor components.
func Mkdev(major, minor uint32) uint64 { func Mkdev(major, minor uint32) uint64 {
return uint64((major << 8) | minor) return (uint64(major) << 8) | uint64(minor)
} }
...@@ -22,8 +22,8 @@ func Minor(dev uint64) uint32 { ...@@ -22,8 +22,8 @@ func Minor(dev uint64) uint32 {
// Mkdev returns a NetBSD device number generated from the given major and minor // Mkdev returns a NetBSD device number generated from the given major and minor
// components. // components.
func Mkdev(major, minor uint32) uint64 { func Mkdev(major, minor uint32) uint64 {
dev := uint64((major << 8) & 0x000fff00) dev := (uint64(major) << 8) & 0x000fff00
dev |= uint64((minor << 12) & 0xfff00000) dev |= (uint64(minor) << 12) & 0xfff00000
dev |= uint64((minor << 0) & 0x000000ff) dev |= (uint64(minor) << 0) & 0x000000ff
return dev return dev
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment