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 @@ -252,15 +252,20 @@ func (l deviceLib) getDeviceMajor(name string) (int, error) {
252252 return - 1 , fmt .Errorf ("error parsing '%s': unexpected regex match: %v" , procDevicesPath , matches )
253253 }
254254
255- // Convert capture group content to integer. Error should be unreachable
256- // (because capture group has matched [0-9]+ which should always convert to
257- // integer).
258- major , err := strconv .Atoi (matches [1 ])
255+ // Convert capture group content to integer. Perform upper bound check:
256+ // value must fit into 32-bit integer (it's then also guaranteed to fit into
257+ // a 32-bit unsigned integer, which is the type that must be passed to
258+ // unix.Mkdev()).
259+ major , err := strconv .ParseInt (matches [1 ], 10 , 32 )
259260 if err != nil {
260261 return - 1 , fmt .Errorf ("int conversion failed for '%v': %w" , matches [1 ], err )
261262 }
262263
263- return major , nil
264+ // ParseInt() always returns an integer of explicit type `int64`. We have
265+ // performed an upper bound check so it's safe to convert this to `int`
266+ // (which is documented as "int is a signed integer type that is at least 32
267+ // bits in size", so in theory it could be smaller than int64).
268+ return int (major ), nil
264269}
265270
266271func (l deviceLib ) parseNVCapDeviceInfo (nvcapsFilePath string ) (* nvcapDeviceInfo , error ) {
You can’t perform that action at this time.
0 commit comments