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; return VLC_EGENERIC;
if (c >= 'a' && c <= 'f') if (*string_hexa != 'x' && *string_hexa != 'X')
return c - 'a' + 10; return VLC_EGENERIC;
return -1;
}
static int string_to_IV(const char *string_hexa, uint8_t iv[AES_BLOCK_SIZE]) string_hexa++;
{
const char *p = string_hexa;
uint8_t *d = iv;
unsigned int c;
if (*p++ != '0') size_t len = strlen(string_hexa);
if (len <= 16) {
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; return VLC_EGENERIC;
if (*p++ != 'x') string_hexa[len-16] = '\0';
iv_hi = strtoull(string_hexa, NULL, 16);
if (end)
return VLC_EGENERIC; return VLC_EGENERIC;
}
while (*p && *(p+1)) for (int i = 8; i ; --i) {
{ iv[ i] = iv_hi & 0xff;
c = hex2int(*p++) << 4; iv[8+i] = iv_lo & 0xff;
c |= hex2int(*p++); iv_hi >>= 8;
*d++ = c; 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