Skip to content

Commit 248ab3d

Browse files
committed
Change SystemInfoParam BlockData field type from array to slice (#51)
1 parent 7216f57 commit 248ab3d

File tree

2 files changed

+72
-33
lines changed

2 files changed

+72
-33
lines changed

cmd_get_system_info_params.go

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
134134
}
135135
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
136136
return err
137-
} else {
138-
stringLength := uint8(p.BlockData[1])
139-
setsCount = stringLength/16 + 1
140137
}
138+
if len(p.BlockData) < 2 {
139+
// For the first block of string data (set selector = 0),
140+
// the first two bytes indicate the encoding of the string and its overall length as follows.
141+
// So, if the length is less than 2, it means there is no string data.
142+
return nil
143+
}
144+
stringLength := uint8(p.BlockData[1])
145+
setsCount = stringLength/16 + 1
141146

142147
params.SystemFirmwareVersions = make([]*SystemInfoParam_SystemFirmwareVersion, setsCount)
143148
for i := uint8(0); i < setsCount; i++ {
@@ -164,10 +169,12 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
164169
}
165170
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
166171
return err
167-
} else {
168-
stringLength := uint8(p.BlockData[1])
169-
setsCount = stringLength/16 + 1
170172
}
173+
if len(p.BlockData) < 2 {
174+
return nil
175+
}
176+
stringLength := uint8(p.BlockData[1])
177+
setsCount = stringLength/16 + 1
171178

172179
params.SystemNames = make([]*SystemInfoParam_SystemName, setsCount)
173180
for i := uint8(0); i < setsCount; i++ {
@@ -194,10 +201,12 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
194201
}
195202
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
196203
return err
197-
} else {
198-
stringLength := uint8(p.BlockData[1])
199-
setsCount = stringLength/16 + 1
200204
}
205+
if len(p.BlockData) < 2 {
206+
return nil
207+
}
208+
stringLength := uint8(p.BlockData[1])
209+
setsCount = stringLength/16 + 1
201210

202211
params.PrimaryOSNames = make([]*SystemInfoParam_PrimaryOSName, setsCount)
203212
for i := uint8(0); i < setsCount; i++ {
@@ -224,10 +233,12 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
224233
}
225234
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
226235
return err
227-
} else {
228-
stringLength := uint8(p.BlockData[1])
229-
setsCount = stringLength/16 + 1
230236
}
237+
if len(p.BlockData) < 2 {
238+
return nil
239+
}
240+
stringLength := uint8(p.BlockData[1])
241+
setsCount = stringLength/16 + 1
231242

232243
params.OSNames = make([]*SystemInfoParam_OSName, setsCount)
233244
for i := uint8(0); i < setsCount; i++ {
@@ -254,10 +265,12 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
254265
}
255266
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
256267
return err
257-
} else {
258-
stringLength := uint8(p.BlockData[1])
259-
setsCount = stringLength/16 + 1
260268
}
269+
if len(p.BlockData) < 2 {
270+
return nil
271+
}
272+
stringLength := uint8(p.BlockData[1])
273+
setsCount = stringLength/16 + 1
261274

262275
params.OSVersions = make([]*SystemInfoParam_OSVersion, setsCount)
263276
for i := uint8(0); i < setsCount; i++ {
@@ -283,8 +296,9 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
283296
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
284297
return err
285298
}
286-
287-
//stringDataType := uint8(p.BlockData[0])
299+
if len(p.BlockData) < 2 {
300+
return nil
301+
}
288302
stringLength := uint8(p.BlockData[1]) // string length 1-based
289303
setsCount := stringLength/16 + 1
290304

@@ -312,8 +326,9 @@ func (c *Client) GetSystemInfoParamsFor(ctx context.Context, params *SystemInfoP
312326
if err := c.GetSystemInfoParamFor(ctx, p); canIgnore(err) != nil {
313327
return err
314328
}
315-
316-
//stringDataType := uint8(p.BlockData[0])
329+
if len(p.BlockData) < 2 {
330+
return nil
331+
}
317332
stringLength := uint8(p.BlockData[1]) // string length 1-based
318333
setsCount := stringLength/16 + 1
319334

types_system_info_params.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (p *SystemInfoParam_SetInProgress) Format() string {
209209

210210
type SystemInfoParam_SystemFirmwareVersion struct {
211211
SetSelector uint8
212-
BlockData [16]byte
212+
BlockData []byte
213213
}
214214

215215
func (p *SystemInfoParam_SystemFirmwareVersion) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -228,7 +228,11 @@ func (p *SystemInfoParam_SystemFirmwareVersion) Unpack(data []byte) error {
228228
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
229229
}
230230
p.SetSelector = data[0]
231-
copy(p.BlockData[:], data[1:])
231+
232+
if len(data) > 1 {
233+
p.BlockData = make([]byte, len(data)-1)
234+
copy(p.BlockData[:], data[1:])
235+
}
232236
return nil
233237
}
234238

@@ -241,7 +245,7 @@ func (p *SystemInfoParam_SystemFirmwareVersion) Format() string {
241245

242246
type SystemInfoParam_SystemName struct {
243247
SetSelector uint8
244-
BlockData [16]byte
248+
BlockData []byte
245249
}
246250

247251
func (p *SystemInfoParam_SystemName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -260,7 +264,11 @@ func (p *SystemInfoParam_SystemName) Unpack(data []byte) error {
260264
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
261265
}
262266
p.SetSelector = data[0]
263-
copy(p.BlockData[:], data[1:])
267+
268+
if len(data) > 1 {
269+
p.BlockData = make([]byte, len(data)-1)
270+
copy(p.BlockData[:], data[1:])
271+
}
264272
return nil
265273
}
266274

@@ -273,7 +281,7 @@ func (p *SystemInfoParam_SystemName) Format() string {
273281

274282
type SystemInfoParam_PrimaryOSName struct {
275283
SetSelector uint8
276-
BlockData [16]byte
284+
BlockData []byte
277285
}
278286

279287
func (p *SystemInfoParam_PrimaryOSName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -292,7 +300,10 @@ func (p *SystemInfoParam_PrimaryOSName) Unpack(data []byte) error {
292300
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
293301
}
294302
p.SetSelector = data[0]
295-
copy(p.BlockData[:], data[1:])
303+
if len(data) > 1 {
304+
p.BlockData = make([]byte, len(data)-1)
305+
copy(p.BlockData[:], data[1:])
306+
}
296307
return nil
297308
}
298309

@@ -305,7 +316,7 @@ func (p *SystemInfoParam_PrimaryOSName) Format() string {
305316

306317
type SystemInfoParam_OSName struct {
307318
SetSelector uint8
308-
BlockData [16]byte
319+
BlockData []byte
309320
}
310321

311322
func (p *SystemInfoParam_OSName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -324,7 +335,11 @@ func (p *SystemInfoParam_OSName) Unpack(data []byte) error {
324335
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
325336
}
326337
p.SetSelector = data[0]
327-
copy(p.BlockData[:], data[1:])
338+
339+
if len(data) > 1 {
340+
p.BlockData = make([]byte, len(data)-1)
341+
copy(p.BlockData[:], data[1:])
342+
}
328343
return nil
329344
}
330345

@@ -337,7 +352,7 @@ func (p *SystemInfoParam_OSName) Format() string {
337352

338353
type SystemInfoParam_OSVersion struct {
339354
SetSelector uint8
340-
BlockData [16]byte
355+
BlockData []byte
341356
}
342357

343358
func (p *SystemInfoParam_OSVersion) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -356,7 +371,10 @@ func (p *SystemInfoParam_OSVersion) Unpack(data []byte) error {
356371
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
357372
}
358373
p.SetSelector = data[0]
359-
copy(p.BlockData[:], data[1:])
374+
if len(data) > 1 {
375+
p.BlockData = make([]byte, len(data)-1)
376+
copy(p.BlockData[:], data[1:])
377+
}
360378
return nil
361379
}
362380

@@ -369,7 +387,7 @@ func (p *SystemInfoParam_OSVersion) Format() string {
369387

370388
type SystemInfoParam_BMCURL struct {
371389
SetSelector uint8
372-
BlockData [16]byte
390+
BlockData []byte
373391
}
374392

375393
func (p *SystemInfoParam_BMCURL) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -388,7 +406,10 @@ func (p *SystemInfoParam_BMCURL) Unpack(data []byte) error {
388406
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
389407
}
390408
p.SetSelector = data[0]
391-
copy(p.BlockData[:], data[1:])
409+
if len(data) > 1 {
410+
p.BlockData = make([]byte, len(data)-1)
411+
copy(p.BlockData[:], data[1:])
412+
}
392413
return nil
393414
}
394415

@@ -401,7 +422,7 @@ func (p *SystemInfoParam_BMCURL) Format() string {
401422

402423
type SystemInfoParam_ManagementURL struct {
403424
SetSelector uint8
404-
BlockData [16]byte
425+
BlockData []byte
405426
}
406427

407428
func (p *SystemInfoParam_ManagementURL) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
@@ -420,7 +441,10 @@ func (p *SystemInfoParam_ManagementURL) Unpack(data []byte) error {
420441
return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
421442
}
422443
p.SetSelector = data[0]
423-
copy(p.BlockData[:], data[1:])
444+
if len(data) > 1 {
445+
p.BlockData = make([]byte, len(data)-1)
446+
copy(p.BlockData[:], data[1:])
447+
}
424448
return nil
425449
}
426450

0 commit comments

Comments
 (0)