diff options
author | Lukasz Marek <lukasz.m.luki2@gmail.com> | 2014-11-25 20:25:10 +0100 |
---|---|---|
committer | Lukasz Marek <lukasz.m.luki2@gmail.com> | 2014-11-29 00:58:42 +0100 |
commit | 0cb994dfe32efa97024962f8e46c0738722ba159 (patch) | |
tree | bb589eab98ab1606df43bab8bb471703fa050a4a /libavutil/opt.c | |
parent | dd5d61795690e339ae271692e7ab9df66b5eb153 (diff) | |
download | ffmpeg-0cb994dfe32efa97024962f8e46c0738722ba159.tar.gz |
lavu/opt: add escaping to av_opt_serialize
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r-- | libavutil/opt.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c index 64ce896833..d873bd205e 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1846,6 +1846,13 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, uint8_t *buf; AVBPrint bprint; int ret, cnt = 0; + const char special_chars[] = {pairs_sep, key_val_sep, '\0'}; + + if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep || + pairs_sep == '\\' || key_val_sep == '\\') { + av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found."); + return AVERROR(EINVAL); + } if (!obj || !buffer) return AVERROR(EINVAL); @@ -1869,7 +1876,9 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, if (buf) { if (cnt++) av_bprint_append_data(&bprint, &pairs_sep, 1); - av_bprintf(&bprint, "%s%c%s", o->name, key_val_sep, buf); + av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); + av_bprint_append_data(&bprint, &key_val_sep, 1); + av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); av_freep(&buf); } } @@ -1903,6 +1912,7 @@ typedef struct TestContext int64_t num64; float flt; double dbl; + char *escape; } TestContext; #define OFFSET(x) offsetof(TestContext, x) @@ -1916,6 +1926,7 @@ static const AVOption test_options[]= { {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1 }, {"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 1}, 0, 10 }, {"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, {.str = "default"}, CHAR_MIN, CHAR_MAX }, +{"escape", "set escape str", OFFSET(escape), AV_OPT_TYPE_STRING, {.str = "\\=,"}, CHAR_MIN, CHAR_MAX }, {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 1}, 0, INT_MAX, 0, "flags" }, {"cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" }, {"lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" }, @@ -1960,6 +1971,7 @@ int main(void) printf("num=%d\n", test_ctx.num); printf("toggle=%d\n", test_ctx.toggle); printf("string=%s\n", test_ctx.string); + printf("escape=%s\n", test_ctx.escape); printf("flags=%d\n", test_ctx.flags); printf("rational=%d/%d\n", test_ctx.rational.num, test_ctx.rational.den); printf("video_rate=%d/%d\n", test_ctx.video_rate.num, test_ctx.video_rate.den); |