Commit a7b544a4 authored by Rafaël Carré's avatar Rafaël Carré Committed by Jean-Baptiste Kempf

HLS: fix IV parsing

Don't assume IV has 32 digits (leading zeroes are not mentioned in the
spec)
(cherry picked from commit a75552b81ca070dced73f42873c3c52c4d75f4a7)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent ec29285a
...@@ -502,33 +502,38 @@ static char *parse_Attributes(const char *line, const char *attr) ...@@ -502,33 +502,38 @@ static char *parse_Attributes(const char *line, const char *attr)
return NULL; return NULL;
} }
static int hex2int(char c) static int string_to_IV(char *string_hexa, uint8_t iv[AES_BLOCK_SIZE])
{ {
if (c >= '0' && c <= '9') unsigned long long iv_hi, iv_lo;
return c - '0'; char *end = NULL;
if (c >= 'A' && c <= 'F') if (*string_hexa++ != '0')
return c - 'A' + 10;
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
return -1;
}
static int string_to_IV(const char *string_hexa, uint8_t iv[AES_BLOCK_SIZE])
{
const char *p = string_hexa;
uint8_t *d = iv;
unsigned int c;
if (*p++ != '0')
return VLC_EGENERIC; return VLC_EGENERIC;
if (*p++ != 'x') if (*string_hexa != 'x' && *string_hexa != 'X')
return VLC_EGENERIC; return VLC_EGENERIC;
while (*p && *(p+1)) string_hexa++;
{
c = hex2int(*p++) << 4; size_t len = strlen(string_hexa);
c |= hex2int(*p++); if (len <= 16) {
*d++ = c; iv_hi = 0;
iv_lo = strtoull(string_hexa, &end, 16);
if (end)
return VLC_EGENERIC;
} else {
iv_lo = strtoull(&string_hexa[len-16], NULL, 16);
if (end)
return VLC_EGENERIC;
string_hexa[len-16] = '\0';
iv_hi = strtoull(string_hexa, NULL, 16);
if (end)
return VLC_EGENERIC;
}
for (int i = 8; i ; --i) {
iv[ i] = iv_hi & 0xff;
iv[8+i] = iv_lo & 0xff;
iv_hi >>= 8;
iv_lo >>= 8;
} }
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -790,7 +795,10 @@ static int parse_Key(stream_t *s, hls_stream_t *hls, char *p_read) ...@@ -790,7 +795,10 @@ static int parse_Key(stream_t *s, hls_stream_t *hls, char *p_read)
*/ */
if (string_to_IV(iv, hls->psz_AES_IV) == VLC_EGENERIC) if (string_to_IV(iv, hls->psz_AES_IV) == VLC_EGENERIC)
{
msg_Err(s, "IV invalid");
err = VLC_EGENERIC; err = VLC_EGENERIC;
}
else else
hls->b_iv_loaded = true; hls->b_iv_loaded = true;
free(value); free(value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment