avformat/utils: Make ff_data_to_hex() zero-terminate the string
Most callers want it that way anyway. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
b09ea67b40
commit
e38eaf4749
|
@ -1284,7 +1284,6 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg,
|
||||||
char iv[33], key[33], url[MAX_URL_SIZE];
|
char iv[33], key[33], url[MAX_URL_SIZE];
|
||||||
ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
|
ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
|
||||||
ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
|
ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
|
||||||
iv[32] = key[32] = '\0';
|
|
||||||
if (strstr(seg->url, "://"))
|
if (strstr(seg->url, "://"))
|
||||||
snprintf(url, sizeof(url), "crypto+%s", seg->url);
|
snprintf(url, sizeof(url), "crypto+%s", seg->url);
|
||||||
else
|
else
|
||||||
|
@ -2074,7 +2073,6 @@ static int hls_read_header(AVFormatContext *s)
|
||||||
if (strstr(in_fmt->name, "mov")) {
|
if (strstr(in_fmt->name, "mov")) {
|
||||||
char key[33];
|
char key[33];
|
||||||
ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
|
ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
|
||||||
key[32] = '\0';
|
|
||||||
av_dict_set(&options, "decryption_key", key, AV_OPT_FLAG_DECODING_PARAM);
|
av_dict_set(&options, "decryption_key", key, AV_OPT_FLAG_DECODING_PARAM);
|
||||||
} else if (!c->crypto_ctx.aes_ctx) {
|
} else if (!c->crypto_ctx.aes_ctx) {
|
||||||
c->crypto_ctx.aes_ctx = av_aes_alloc();
|
c->crypto_ctx.aes_ctx = av_aes_alloc();
|
||||||
|
|
|
@ -745,7 +745,6 @@ static int do_encrypt(AVFormatContext *s, VariantStream *vs)
|
||||||
memcpy(iv, hls->iv, sizeof(iv));
|
memcpy(iv, hls->iv, sizeof(iv));
|
||||||
}
|
}
|
||||||
ff_data_to_hex(buf, iv, sizeof(iv), 0);
|
ff_data_to_hex(buf, iv, sizeof(iv), 0);
|
||||||
buf[32] = '\0';
|
|
||||||
memcpy(hls->iv_string, buf, sizeof(hls->iv_string));
|
memcpy(hls->iv_string, buf, sizeof(hls->iv_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,6 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username,
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
cnonce_buf[i] = av_get_random_seed();
|
cnonce_buf[i] = av_get_random_seed();
|
||||||
ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);
|
ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);
|
||||||
cnonce[2*sizeof(cnonce_buf)] = 0;
|
|
||||||
|
|
||||||
md5ctx = av_md5_alloc();
|
md5ctx = av_md5_alloc();
|
||||||
if (!md5ctx)
|
if (!md5ctx)
|
||||||
|
@ -166,7 +165,6 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username,
|
||||||
update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL);
|
update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL);
|
||||||
av_md5_final(md5ctx, hash);
|
av_md5_final(md5ctx, hash);
|
||||||
ff_data_to_hex(A1hash, hash, 16, 1);
|
ff_data_to_hex(A1hash, hash, 16, 1);
|
||||||
A1hash[32] = 0;
|
|
||||||
|
|
||||||
if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {
|
if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) {
|
||||||
} else if (!strcmp(digest->algorithm, "MD5-sess")) {
|
} else if (!strcmp(digest->algorithm, "MD5-sess")) {
|
||||||
|
@ -174,7 +172,6 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username,
|
||||||
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL);
|
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL);
|
||||||
av_md5_final(md5ctx, hash);
|
av_md5_final(md5ctx, hash);
|
||||||
ff_data_to_hex(A1hash, hash, 16, 1);
|
ff_data_to_hex(A1hash, hash, 16, 1);
|
||||||
A1hash[32] = 0;
|
|
||||||
} else {
|
} else {
|
||||||
/* Unsupported algorithm */
|
/* Unsupported algorithm */
|
||||||
av_free(md5ctx);
|
av_free(md5ctx);
|
||||||
|
@ -185,7 +182,6 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username,
|
||||||
update_md5_strings(md5ctx, method, ":", uri, NULL);
|
update_md5_strings(md5ctx, method, ":", uri, NULL);
|
||||||
av_md5_final(md5ctx, hash);
|
av_md5_final(md5ctx, hash);
|
||||||
ff_data_to_hex(A2hash, hash, 16, 1);
|
ff_data_to_hex(A2hash, hash, 16, 1);
|
||||||
A2hash[32] = 0;
|
|
||||||
|
|
||||||
av_md5_init(md5ctx);
|
av_md5_init(md5ctx);
|
||||||
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);
|
update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL);
|
||||||
|
@ -195,7 +191,6 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username,
|
||||||
update_md5_strings(md5ctx, ":", A2hash, NULL);
|
update_md5_strings(md5ctx, ":", A2hash, NULL);
|
||||||
av_md5_final(md5ctx, hash);
|
av_md5_final(md5ctx, hash);
|
||||||
ff_data_to_hex(response, hash, 16, 1);
|
ff_data_to_hex(response, hash, 16, 1);
|
||||||
response[32] = 0;
|
|
||||||
|
|
||||||
av_free(md5ctx);
|
av_free(md5ctx);
|
||||||
|
|
||||||
|
|
|
@ -484,6 +484,17 @@ void ff_flush_packet_queue(AVFormatContext *s);
|
||||||
*/
|
*/
|
||||||
int ff_mkdir_p(const char *path);
|
int ff_mkdir_p(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write hexadecimal string corresponding to given binary data. The string
|
||||||
|
* is zero-terminated.
|
||||||
|
*
|
||||||
|
* @param buf the output string is written here;
|
||||||
|
* needs to be at least 2 * size + 1 bytes long.
|
||||||
|
* @param src the input data to be transformed.
|
||||||
|
* @param size the size (in byte) of src.
|
||||||
|
* @param lowercase determines whether to use the range [0-9a-f] or [0-9A-F].
|
||||||
|
* @return buf.
|
||||||
|
*/
|
||||||
char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
|
char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4290,7 +4290,6 @@ static void param_write_hex(AVIOContext *pb, const char *name, const uint8_t *va
|
||||||
char buf[150];
|
char buf[150];
|
||||||
len = FFMIN(sizeof(buf) / 2 - 1, len);
|
len = FFMIN(sizeof(buf) / 2 - 1, len);
|
||||||
ff_data_to_hex(buf, value, len, 0);
|
ff_data_to_hex(buf, value, len, 0);
|
||||||
buf[2 * len] = '\0';
|
|
||||||
avio_printf(pb, "<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
|
avio_printf(pb, "<param name=\"%s\" value=\"%s\" valuetype=\"data\"/>\n", name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,6 @@ static void hex_log(AVFormatContext *s, int level,
|
||||||
if (av_log_get_level() < level)
|
if (av_log_get_level() < level)
|
||||||
return;
|
return;
|
||||||
ff_data_to_hex(buf, value, len, 1);
|
ff_data_to_hex(buf, value, len, 1);
|
||||||
buf[len << 1] = '\0';
|
|
||||||
av_log(s, level, "%s: %s\n", name, buf);
|
av_log(s, level, "%s: %s\n", name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1663,7 +1663,6 @@ static int do_llnw_auth(RTMPContext *rt, const char *user, const char *nonce)
|
||||||
av_md5_update(md5, rt->password, strlen(rt->password));
|
av_md5_update(md5, rt->password, strlen(rt->password));
|
||||||
av_md5_final(md5, hash);
|
av_md5_final(md5, hash);
|
||||||
ff_data_to_hex(hashstr1, hash, 16, 1);
|
ff_data_to_hex(hashstr1, hash, 16, 1);
|
||||||
hashstr1[32] = '\0';
|
|
||||||
|
|
||||||
av_md5_init(md5);
|
av_md5_init(md5);
|
||||||
av_md5_update(md5, method, strlen(method));
|
av_md5_update(md5, method, strlen(method));
|
||||||
|
@ -1673,7 +1672,6 @@ static int do_llnw_auth(RTMPContext *rt, const char *user, const char *nonce)
|
||||||
av_md5_update(md5, "/_definst_", strlen("/_definst_"));
|
av_md5_update(md5, "/_definst_", strlen("/_definst_"));
|
||||||
av_md5_final(md5, hash);
|
av_md5_final(md5, hash);
|
||||||
ff_data_to_hex(hashstr2, hash, 16, 1);
|
ff_data_to_hex(hashstr2, hash, 16, 1);
|
||||||
hashstr2[32] = '\0';
|
|
||||||
|
|
||||||
av_md5_init(md5);
|
av_md5_init(md5);
|
||||||
av_md5_update(md5, hashstr1, strlen(hashstr1));
|
av_md5_update(md5, hashstr1, strlen(hashstr1));
|
||||||
|
|
|
@ -216,7 +216,6 @@ static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par)
|
||||||
memcpy(p, profile_string, strlen(profile_string));
|
memcpy(p, profile_string, strlen(profile_string));
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
ff_data_to_hex(p, sps + 1, 3, 0);
|
ff_data_to_hex(p, sps + 1, 3, 0);
|
||||||
p[6] = '\0';
|
|
||||||
}
|
}
|
||||||
av_free(tmpbuf);
|
av_free(tmpbuf);
|
||||||
|
|
||||||
|
@ -340,7 +339,6 @@ static char *extradata2config(AVFormatContext *s, AVCodecParameters *par)
|
||||||
}
|
}
|
||||||
memcpy(config, "; config=", 9);
|
memcpy(config, "; config=", 9);
|
||||||
ff_data_to_hex(config + 9, par->extradata, par->extradata_size, 0);
|
ff_data_to_hex(config + 9, par->extradata, par->extradata_size, 0);
|
||||||
config[9 + par->extradata_size * 2] = 0;
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -475,7 +473,6 @@ static char *latm_context2config(AVFormatContext *s, AVCodecParameters *par)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ff_data_to_hex(config, config_byte, 6, 1);
|
ff_data_to_hex(config, config_byte, 6, 1);
|
||||||
config[12] = 0;
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,6 @@ static int tak_read_header(AVFormatContext *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
ff_data_to_hex(md5_hex, md5, sizeof(md5), 1);
|
ff_data_to_hex(md5_hex, md5, sizeof(md5), 1);
|
||||||
md5_hex[2 * sizeof(md5)] = '\0';
|
|
||||||
av_log(s, AV_LOG_VERBOSE, "MD5=%s\n", md5_hex);
|
av_log(s, AV_LOG_VERBOSE, "MD5=%s\n", md5_hex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1151,6 +1151,7 @@ char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
|
||||||
buff[i * 2] = hex_table[src[i] >> 4];
|
buff[i * 2] = hex_table[src[i] >> 4];
|
||||||
buff[i * 2 + 1] = hex_table[src[i] & 0xF];
|
buff[i * 2 + 1] = hex_table[src[i] & 0xF];
|
||||||
}
|
}
|
||||||
|
buff[2 * s] = '\0';
|
||||||
|
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue