[Asterisk-code-review] res_http_media_cache: Do not crash when there is no extension (asterisk[master])
George Joseph
asteriskteam at digium.com
Wed Jan 4 05:16:54 CST 2023
George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19761 )
Change subject: res_http_media_cache: Do not crash when there is no extension
......................................................................
res_http_media_cache: Do not crash when there is no extension
Do not crash when a URL has no path component as in this case the
ast_uri_path function will return NULL. Make the code cope with not
having a path.
The below would crash
> media cache create http://google.com /tmp/foo.wav
Thread 1 "asterisk" received signal SIGSEGV, Segmentation fault.
0x0000ffff836616cc in strrchr () from /lib/aarch64-linux-gnu/libc.so.6
(gdb) bt
#0 0x0000ffff836616cc in strrchr () from /lib/aarch64-linux-gnu/libc.so.6
#1 0x0000ffff43d43a78 in file_extension_from_string (str=<optimized out>, buffer=buffer at entry=0xffffca9973c0 "",
capacity=capacity at entry=64) at res_http_media_cache.c:288
#2 0x0000ffff43d43bac in file_extension_from_url_path (bucket_file=bucket_file at entry=0x3bf96568,
buffer=buffer at entry=0xffffca9973c0 "", capacity=capacity at entry=64) at res_http_media_cache.c:378
#3 0x0000ffff43d43c74 in bucket_file_set_extension (bucket_file=bucket_file at entry=0x3bf96568) at res_http_media_cache.c:392
#4 0x0000ffff43d43d10 in bucket_file_run_curl (bucket_file=0x3bf96568) at res_http_media_cache.c:555
#5 0x0000ffff43d43f74 in bucket_http_wizard_create (sorcery=<optimized out>, data=<optimized out>, object=<optimized out>)
at res_http_media_cache.c:613
#6 0x0000000000487638 in bucket_file_wizard_create (sorcery=<optimized out>, data=<optimized out>, object=<optimized out>)
at bucket.c:191
#7 0x0000000000554408 in sorcery_wizard_create (object_wizard=object_wizard at entry=0x3b9f0718,
details=details at entry=0xffffca9974a8) at sorcery.c:2027
#8 0x0000000000559698 in ast_sorcery_create (sorcery=<optimized out>, object=object at entry=0x3bf96568) at sorcery.c:2077
#9 0x00000000004893a4 in ast_bucket_file_create (file=file at entry=0x3bf96568) at bucket.c:727
#10 0x00000000004f877c in ast_media_cache_create_or_update (uri=0x3bfa1103 "https://google.com",
file_path=0x3bfa1116 "/tmp/foo.wav", metadata=metadata at entry=0x0) at media_cache.c:335
#11 0x00000000004f88ec in media_cache_handle_create_item (e=<optimized out>, cmd=<optimized out>, a=0xffffca9976b8)
at media_cache.c:640
ASTERISK-30375 #close
Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273
---
M res/res_http_media_cache.c
1 file changed, 49 insertions(+), 1 deletion(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Sean Bright: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index cd5fe42..b4c4c65 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -240,6 +240,7 @@
static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)
{
+ const char *path;
struct ast_uri *uri;
uri = ast_uri_parse(ast_sorcery_object_get_id(bucket_file));
@@ -249,8 +250,14 @@
return NULL;
}
+ path = ast_uri_path(uri);
+ if (!path) {
+ ao2_cleanup(uri);
+ return NULL;
+ }
+
/* Just parse it as a string like before, but without the extra cruft */
- buffer = file_extension_from_string(ast_uri_path(uri), buffer, capacity);
+ buffer = file_extension_from_string(path, buffer, capacity);
ao2_cleanup(uri);
return buffer;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19761
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273
Gerrit-Change-Number: 19761
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-CC: Holger Hans Peter Freyther <automatic at freyther.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230104/0afe9fca/attachment-0001.html>
More information about the asterisk-code-review
mailing list