Skip to content

Commit 49c04ce

Browse files
committed
codeql: fix labeler issues
Signed-off-by: Tuomas Katila <tuomas.katila@intel.com>
1 parent 18049f3 commit 49c04ce

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

cmd/internal/labeler/labeler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package labeler
1616

1717
import (
1818
"fmt"
19+
"math"
1920
"os"
2021
"os/signal"
2122
"path"
@@ -205,11 +206,16 @@ func (l *labeler) getNumaNode(gpuName string) int {
205206
return -1
206207
}
207208

208-
numa, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
209+
numa, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 32)
209210
if err != nil {
210211
klog.Warning("Can't convert numa_node: ", err)
211212
return -1
212213
}
214+
if numa > math.MaxInt16 {
215+
klog.Warning("Too large numa: ", numa)
216+
217+
return -1
218+
}
213219

214220
return int(numa)
215221
}
@@ -305,7 +311,9 @@ func (l *labeler) createLabels() error {
305311
numaMapping[numaNode] = numaList
306312
}
307313

308-
l.labels.addNumericLabel(labelNamespace+"memory.max", int64(memoryAmount))
314+
if memoryAmount < math.MaxInt64 {
315+
l.labels.addNumericLabel(labelNamespace+"memory.max", int64(memoryAmount))
316+
}
309317
}
310318

311319
gpuCount := len(gpuNumList)

cmd/internal/labeler/labeler_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,48 @@ func getTestCases() []testcase {
520520
"gpu.intel.com/tiles": "27",
521521
},
522522
},
523+
{
524+
sysfsdirs: []string{
525+
"card1/device/drm/card1",
526+
"card1/gt/gt0",
527+
},
528+
sysfsfiles: map[string][]byte{
529+
"card1/device/vendor": []byte("0x8086"),
530+
"card1/lmem_total_bytes": []byte("8000"),
531+
"card1/device/numa_node": []byte("2147483648"), // max int32 + 1
532+
},
533+
name: "too large numa node",
534+
memoryOverride: 16000000000,
535+
expectedRetval: nil,
536+
expectedLabels: labelMap{
537+
"gpu.intel.com/millicores": "1000",
538+
"gpu.intel.com/memory.max": "8000",
539+
"gpu.intel.com/gpu-numbers": "1",
540+
"gpu.intel.com/cards": "card1",
541+
"gpu.intel.com/tiles": "1",
542+
},
543+
},
544+
{
545+
sysfsdirs: []string{
546+
"card1/device/drm/card1",
547+
"card1/gt/gt0",
548+
},
549+
sysfsfiles: map[string][]byte{
550+
"card1/device/vendor": []byte("0x8086"),
551+
"card1/lmem_total_bytes": []byte("8000"),
552+
"card1/device/numa_node": []byte("32768"), // max int16 + 1
553+
},
554+
name: "too large numa node",
555+
memoryOverride: 16000000000,
556+
expectedRetval: nil,
557+
expectedLabels: labelMap{
558+
"gpu.intel.com/millicores": "1000",
559+
"gpu.intel.com/memory.max": "8000",
560+
"gpu.intel.com/gpu-numbers": "1",
561+
"gpu.intel.com/cards": "card1",
562+
"gpu.intel.com/tiles": "1",
563+
},
564+
},
523565
}
524566
}
525567

0 commit comments

Comments
 (0)