|
@@ -32,6 +32,7 @@ FILE_LICENCE ( BSD2 );
|
32
|
32
|
|
33
|
33
|
#include <stdlib.h>
|
34
|
34
|
#include <errno.h>
|
|
35
|
+#include <ipxe/base16.h>
|
35
|
36
|
#include <ipxe/srp.h>
|
36
|
37
|
#include <ipxe/infiniband.h>
|
37
|
38
|
#include <ipxe/ib_cmrc.h>
|
|
@@ -78,8 +79,7 @@ static int ib_srp_parse_byte_string ( const char *rp_comp, uint8_t *bytes,
|
78
|
79
|
unsigned int size_flags ) {
|
79
|
80
|
size_t size = ( size_flags & ~IB_SRP_PARSE_FLAG_MASK );
|
80
|
81
|
size_t rp_comp_len = strlen ( rp_comp );
|
81
|
|
- char buf[3];
|
82
|
|
- char *buf_end;
|
|
82
|
+ int decoded_size;
|
83
|
83
|
|
84
|
84
|
/* Allow optional components to be empty */
|
85
|
85
|
if ( ( rp_comp_len == 0 ) &&
|
|
@@ -91,13 +91,11 @@ static int ib_srp_parse_byte_string ( const char *rp_comp, uint8_t *bytes,
|
91
|
91
|
return -EINVAL_BYTE_STRING_LEN;
|
92
|
92
|
|
93
|
93
|
/* Parse byte string */
|
94
|
|
- for ( ; size ; size--, rp_comp += 2, bytes++ ) {
|
95
|
|
- memcpy ( buf, rp_comp, 2 );
|
96
|
|
- buf[2] = '\0';
|
97
|
|
- *bytes = strtoul ( buf, &buf_end, 16 );
|
98
|
|
- if ( buf_end != &buf[2] )
|
99
|
|
- return -EINVAL_BYTE_STRING;
|
100
|
|
- }
|
|
94
|
+ decoded_size = base16_decode ( rp_comp, bytes );
|
|
95
|
+ if ( decoded_size < 0 )
|
|
96
|
+ return decoded_size;
|
|
97
|
+ assert ( decoded_size == size );
|
|
98
|
+
|
101
|
99
|
return 0;
|
102
|
100
|
}
|
103
|
101
|
|