From 7a85bfad8bb9558204b9cc9b3624680d2d443a35 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 12 Sep 2017 13:21:58 +0200 Subject: [PATCH] unix: fix potential overflow in Mkdev on Linux Daniel Swarbrick reports the following go vet warning after CL 50550: .../dev_linux.go:38: (major & 0xfffff000) (32 bits) too small for shift of 32 Fix it by converting major and minor to uint64 before the bitwise-and. Change-Id: If37540be81f2c78a58fd5e5dcce7b770ce7b8afe Reviewed-on: https://go-review.googlesource.com/63090 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- unix/dev_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unix/dev_linux.go b/unix/dev_linux.go index c902c39e..d165d6f3 100644 --- a/unix/dev_linux.go +++ b/unix/dev_linux.go @@ -34,9 +34,9 @@ func Minor(dev uint64) uint32 { // Mkdev returns a Linux device number generated from the given major and minor // components. func Mkdev(major, minor uint32) uint64 { - dev := uint64((major & 0x00000fff) << 8) - dev |= uint64((major & 0xfffff000) << 32) - dev |= uint64((minor & 0x000000ff) << 0) - dev |= uint64((minor & 0xffffff00) << 12) + dev := (uint64(major) & 0x00000fff) << 8 + dev |= (uint64(major) & 0xfffff000) << 32 + dev |= (uint64(minor) & 0x000000ff) << 0 + dev |= (uint64(minor) & 0xffffff00) << 12 return dev }