mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-03-09 08:59:30 +00:00
Several packages are only used while running the e2e suite. These packages are less important to update, as the they can not influence the final executable that is part of the Ceph-CSI container-image. By moving these dependencies out of the main Ceph-CSI go.mod, it is easier to identify if a reported CVE affects Ceph-CSI, or only the testing (like most of the Kubernetes CVEs). Signed-off-by: Niels de Vos <ndevos@ibm.com>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// +build nacl linux js solaris
|
|
|
|
package godirwalk
|
|
|
|
import (
|
|
"bytes"
|
|
"reflect"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
// nameOffset is a compile time constant
|
|
const nameOffset = int(unsafe.Offsetof(syscall.Dirent{}.Name))
|
|
|
|
func nameFromDirent(de *syscall.Dirent) (name []byte) {
|
|
// Because this GOOS' syscall.Dirent does not provide a field that specifies
|
|
// the name length, this function must first calculate the max possible name
|
|
// length, and then search for the NULL byte.
|
|
ml := int(de.Reclen) - nameOffset
|
|
|
|
// Convert syscall.Dirent.Name, which is array of int8, to []byte, by
|
|
// overwriting Cap, Len, and Data slice header fields to the max possible
|
|
// name length computed above, and finding the terminating NULL byte.
|
|
sh := (*reflect.SliceHeader)(unsafe.Pointer(&name))
|
|
sh.Cap = ml
|
|
sh.Len = ml
|
|
sh.Data = uintptr(unsafe.Pointer(&de.Name[0]))
|
|
|
|
if index := bytes.IndexByte(name, 0); index >= 0 {
|
|
// Found NULL byte; set slice's cap and len accordingly.
|
|
sh.Cap = index
|
|
sh.Len = index
|
|
return
|
|
}
|
|
|
|
// NOTE: This branch is not expected, but included for defensive
|
|
// programming, and provides a hard stop on the name based on the structure
|
|
// field array size.
|
|
sh.Cap = len(de.Name)
|
|
sh.Len = sh.Cap
|
|
return
|
|
}
|