diff options
author | Michael Brown | 2015-04-24 15:34:32 +0200 |
---|---|---|
committer | Michael Brown | 2015-04-24 15:41:32 +0200 |
commit | 9aa8090d069eb0b36769f33544faf0e7e429e844 (patch) | |
tree | 02dd0bdc5afca6e625f2f6c73fd85244ab020093 /src/net/tcp/httpcore.c | |
parent | [test] Include IPv6 support when performing settings self-tests (diff) | |
download | ipxe-9aa8090d069eb0b36769f33544faf0e7e429e844.tar.gz ipxe-9aa8090d069eb0b36769f33544faf0e7e429e844.tar.xz ipxe-9aa8090d069eb0b36769f33544faf0e7e429e844.zip |
[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/httpcore.c')
-rw-r--r-- | src/net/tcp/httpcore.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/net/tcp/httpcore.c b/src/net/tcp/httpcore.c index 42a0f90e..d94ab5f0 100644 --- a/src/net/tcp/httpcore.c +++ b/src/net/tcp/httpcore.c @@ -1122,12 +1122,14 @@ static void http_digest_update ( struct md5_context *ctx, const char *string ) { * * @v ctx Digest context * @v out Buffer for digest output + * @v len Buffer length */ -static void http_digest_final ( struct md5_context *ctx, char *out ) { +static void http_digest_final ( struct md5_context *ctx, char *out, + size_t len ) { uint8_t digest[MD5_DIGEST_SIZE]; digest_final ( &md5_algorithm, ctx, digest ); - base16_encode ( digest, sizeof ( digest ), out ); + base16_encode ( digest, sizeof ( digest ), out, len ); } /** @@ -1172,20 +1174,20 @@ static char * http_digest_auth ( struct http_request *http, http_digest_update ( &ctx, user ); http_digest_update ( &ctx, realm ); http_digest_update ( &ctx, password ); - http_digest_final ( &ctx, ha1 ); + http_digest_final ( &ctx, ha1, sizeof ( ha1 ) ); if ( md5sess ) { http_digest_init ( &ctx ); http_digest_update ( &ctx, ha1 ); http_digest_update ( &ctx, nonce ); http_digest_update ( &ctx, cnonce ); - http_digest_final ( &ctx, ha1 ); + http_digest_final ( &ctx, ha1, sizeof ( ha1 ) ); } /* Generate HA2 */ http_digest_init ( &ctx ); http_digest_update ( &ctx, method ); http_digest_update ( &ctx, uri ); - http_digest_final ( &ctx, ha2 ); + http_digest_final ( &ctx, ha2, sizeof ( ha2 ) ); /* Generate response */ http_digest_init ( &ctx ); @@ -1197,7 +1199,7 @@ static char * http_digest_auth ( struct http_request *http, http_digest_update ( &ctx, "auth" /* qop */ ); } http_digest_update ( &ctx, ha2 ); - http_digest_final ( &ctx, response ); + http_digest_final ( &ctx, response, sizeof ( response ) ); /* Generate the authorisation string */ len = asprintf ( &auth, "Authorization: Digest username=\"%s\", " |