History

avformat/tls: check for memory allocation failure when setting options

jackarain committed 3 years ago

Commit 4e3916d1 parent 05ea0451 file · +20 −6Browse files

Unified · Split

libavformat/tls.c+20−6
@@ -30,15 +30,18 @@ · 29 unmodified lines
3030 #include "libavutil/opt.h"
3131 #include "libavutil/parseutils.h"
3232
33−static void set_options(TLSShared *c, const char *uri)
33+static int set_options(TLSShared *c, const char *uri)
3434 {
3535 char buf[1024];
3636 const char *p = strchr(uri, '?');
3737 if (!p)
38− return;
38+ return 0;
3939
40− if (!c->ca_file && av_find_info_tag(buf, sizeof(buf), "cafile", p))
40+ if (!c->ca_file && av_find_info_tag(buf, sizeof(buf), "cafile", p)) {
4141 c->ca_file = av_strdup(buf);
42+ if (!c->ca_file)
43+ return AVERROR(ENOMEM);
44+ }
4245
4346 if (!c->verify && av_find_info_tag(buf, sizeof(buf), "verify", p)) {
4447 char *endptr = NULL;
@@ -47,11 +50,19 @@ static void set_options(TLSShared *c, const char *uri) · 2 unmodified lines
4750 c->verify = 1;
4851 }
4952
50− if (!c->cert_file && av_find_info_tag(buf, sizeof(buf), "cert", p))
53+ if (!c->cert_file && av_find_info_tag(buf, sizeof(buf), "cert", p)) {
5154 c->cert_file = av_strdup(buf);
55+ if (!c->cert_file)
56+ return AVERROR(ENOMEM);
57+ }
5258
53− if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p))
59+ if (!c->key_file && av_find_info_tag(buf, sizeof(buf), "key", p)) {
5460 c->key_file = av_strdup(buf);
61+ if (!c->key_file)
62+ return AVERROR(ENOMEM);
63+ }
64+
65+ return 0;
5566 }
5667
5768 int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AVDictionary **options)
@@ -63,8 +74,11 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV · 5 unmodified lines
6374 const char *proxy_path;
6475 char *env_http_proxy, *env_no_proxy;
6576 int use_proxy;
77+ int ret;
6678
67− set_options(c, uri);
79+ ret = set_options(c, uri);
80+ if (ret < 0)
81+ return ret;
6882
6983 if (c->listen)
7084 snprintf(opts, sizeof(opts), "?listen=1");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t