aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/tcp/iscsi.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2015-04-24 14:34:32 +0100
committerMichael Brown <mcb30@ipxe.org>2015-04-24 14:41:32 +0100
commit9aa8090d069eb0b36769f33544faf0e7e429e844 (patch)
tree02dd0bdc5afca6e625f2f6c73fd85244ab020093 /src/net/tcp/iscsi.c
parentb56b482fa3b48ae99c44cc60a34979f8780b076a (diff)
downloadipxe-9aa8090d069eb0b36769f33544faf0e7e429e844.tar.gz
[base16] Add buffer size parameter to base16_encode() and base16_decode()
The current API for Base16 (and Base64) encoding requires the caller to always provide sufficient buffer space. This prevents the use of the generic encoding/decoding functionality in some situations, such as in formatting the hex setting types. Implement a generic hex_encode() (based on the existing format_hex_setting()), implement base16_encode() and base16_decode() in terms of the more generic hex_encode() and hex_decode(), and update all callers to provide the additional buffer length parameter. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/tcp/iscsi.c')
-rw-r--r--src/net/tcp/iscsi.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c
index 2e420d9ac..e553b2148 100644
--- a/src/net/tcp/iscsi.c
+++ b/src/net/tcp/iscsi.c
@@ -709,7 +709,7 @@ static int iscsi_build_login_request_strings ( struct iscsi_session *iscsi,
char buf[ base16_encoded_len ( iscsi->chap.response_len ) + 1 ];
assert ( iscsi->initiator_username != NULL );
base16_encode ( iscsi->chap.response, iscsi->chap.response_len,
- buf );
+ buf, sizeof ( buf ) );
used += ssnprintf ( data + used, len - used,
"CHAP_N=%s%cCHAP_R=0x%s%c",
iscsi->initiator_username, 0, buf, 0 );
@@ -719,7 +719,7 @@ static int iscsi_build_login_request_strings ( struct iscsi_session *iscsi,
size_t challenge_len = ( sizeof ( iscsi->chap_challenge ) - 1 );
char buf[ base16_encoded_len ( challenge_len ) + 1 ];
base16_encode ( ( iscsi->chap_challenge + 1 ), challenge_len,
- buf );
+ buf, sizeof ( buf ) );
used += ssnprintf ( data + used, len - used,
"CHAP_I=%d%cCHAP_C=0x%s%c",
iscsi->chap_challenge[0], 0, buf, 0 );
@@ -833,15 +833,17 @@ static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
*
* @v encoded Encoded large binary value
* @v raw Raw data
+ * @v len Length of data buffer
* @ret len Length of raw data, or negative error
*/
-static int iscsi_large_binary_decode ( const char *encoded, uint8_t *raw ) {
+static int iscsi_large_binary_decode ( const char *encoded, uint8_t *raw,
+ size_t len ) {
/* Check for initial '0x' or '0b' and decode as appropriate */
if ( *(encoded++) == '0' ) {
switch ( tolower ( *(encoded++) ) ) {
case 'x' :
- return base16_decode ( encoded, raw );
+ return base16_decode ( encoded, raw, len );
case 'b' :
return base64_decode ( encoded, raw );
}
@@ -980,7 +982,7 @@ static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
int rc;
/* Process challenge */
- len = iscsi_large_binary_decode ( value, buf );
+ len = iscsi_large_binary_decode ( value, buf, sizeof ( buf ) );
if ( len < 0 ) {
rc = len;
DBGC ( iscsi, "iSCSI %p invalid CHAP challenge \"%s\": %s\n",
@@ -1065,7 +1067,7 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
chap_respond ( &iscsi->chap );
/* Process response */
- len = iscsi_large_binary_decode ( value, buf );
+ len = iscsi_large_binary_decode ( value, buf, sizeof ( buf ) );
if ( len < 0 ) {
rc = len;
DBGC ( iscsi, "iSCSI %p invalid CHAP response \"%s\": %s\n",