File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
cmd/compute-domain-kubelet-plugin Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -253,15 +253,20 @@ func (l deviceLib) getDeviceMajor(name string) (int, error) {
253253 return - 1 , fmt .Errorf ("error parsing '%s': unexpected regex match: %v" , procDevicesPath , matches )
254254 }
255255
256- // Convert capture group content to integer. Error should be unreachable
257- // (because capture group has matched [0-9]+ which should always convert to
258- // integer).
259- major , err := strconv .Atoi (matches [1 ])
256+ // Convert capture group content to integer. Perform upper bound check:
257+ // value must fit into 32-bit integer (it's then also guaranteed to fit into
258+ // a 32-bit unsigned integer, which is the type that must be passed to
259+ // unix.Mkdev()).
260+ major , err := strconv .ParseInt (matches [1 ], 10 , 32 )
260261 if err != nil {
261262 return - 1 , fmt .Errorf ("int conversion failed for '%v': %w" , matches [1 ], err )
262263 }
263264
264- return major , nil
265+ // ParseInt() always returns an integer of explicit type `int64`. We have
266+ // performed an upper bound check so it's safe to convert this to `int`
267+ // (which is documented as "int is a signed integer type that is at least 32
268+ // bits in size", so in theory it could be smaller than int64).
269+ return int (major ), nil
265270}
266271
267272func (l deviceLib ) parseNVCapDeviceInfo (nvcapsFilePath string ) (* nvcapDeviceInfo , error ) {
You can’t perform that action at this time.
0 commit comments