Skip to content

Commit 56d747e

Browse files
authored
Merge pull request #1610 from tkatila/labeler-codeql
Fix last of codeql issues
2 parents 18049f3 + df83e1b commit 56d747e

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

cmd/internal/labeler/labeler.go

Lines changed: 11 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,12 +206,18 @@ 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
}
213214

215+
if numa > math.MaxInt16 {
216+
klog.Warning("Too large numa: ", numa)
217+
218+
return -1
219+
}
220+
214221
return int(numa)
215222
}
216223

@@ -305,7 +312,9 @@ func (l *labeler) createLabels() error {
305312
numaMapping[numaNode] = numaList
306313
}
307314

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

311320
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

pkg/fpga/dfl_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (f *DflFME) GetPortsNum() int {
236236
}
237237

238238
n, err := strconv.ParseUint(f.PortsNum, 10, 32)
239-
if err != nil || n >= math.MaxInt {
239+
if err != nil || n > math.MaxInt32 {
240240
return -1
241241
}
242242

pkg/fpga/intel_fpga_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (f *IntelFpgaFME) GetPortsNum() int {
241241
}
242242

243243
n, err := strconv.ParseUint(f.PortsNum, 10, 32)
244-
if err != nil || n >= math.MaxInt {
244+
if err != nil || n > math.MaxInt32 {
245245
return -1
246246
}
247247

0 commit comments

Comments
 (0)