mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
This updates vendored runc/libcontainer to 1.1.0, and google/cadvisor to a version updated to runc 1.1.0 (google/cadvisor#3048). Changes in vendor are generated by (roughly): ./hack/pin-dependency.sh github.com/google/cadvisor v0.44.0 ./hack/pin-dependency.sh github.com/opencontainers/runc v1.1.0 ./hack/update-vendor.sh ./hack/lint-dependencies.sh # And follow all its recommendations. ./hack/update-vendor.sh ./hack/update-internal-modules.sh ./hack/lint-dependencies.sh # Re-check everything again. Co-Authored-By: Kir Kolyshkin <kolyshkin@gmail.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package btf
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type stringTable []byte
|
|
|
|
func readStringTable(r io.Reader) (stringTable, error) {
|
|
contents, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("can't read string table: %v", err)
|
|
}
|
|
|
|
if len(contents) < 1 {
|
|
return nil, errors.New("string table is empty")
|
|
}
|
|
|
|
if contents[0] != '\x00' {
|
|
return nil, errors.New("first item in string table is non-empty")
|
|
}
|
|
|
|
if contents[len(contents)-1] != '\x00' {
|
|
return nil, errors.New("string table isn't null terminated")
|
|
}
|
|
|
|
return stringTable(contents), nil
|
|
}
|
|
|
|
func (st stringTable) Lookup(offset uint32) (string, error) {
|
|
if int64(offset) > int64(^uint(0)>>1) {
|
|
return "", fmt.Errorf("offset %d overflows int", offset)
|
|
}
|
|
|
|
pos := int(offset)
|
|
if pos >= len(st) {
|
|
return "", fmt.Errorf("offset %d is out of bounds", offset)
|
|
}
|
|
|
|
if pos > 0 && st[pos-1] != '\x00' {
|
|
return "", fmt.Errorf("offset %d isn't start of a string", offset)
|
|
}
|
|
|
|
str := st[pos:]
|
|
end := bytes.IndexByte(str, '\x00')
|
|
if end == -1 {
|
|
return "", fmt.Errorf("offset %d isn't null terminated", offset)
|
|
}
|
|
|
|
return string(str[:end]), nil
|
|
}
|