[Asterisk-code-review] res_http_media_cache: Do not crash when there is no extension (asterisk[20])
Holger Hans Peter Freyther
asteriskteam at digium.com
Fri Dec 16 06:35:24 CST 2022
Holger Hans Peter Freyther has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19717 )
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. In this case the
ast_uri_path function will return NULL. Make the code cope with
str being NULL.
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
Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273
---
M res/res_http_media_cache.c
1 file changed, 46 insertions(+), 5 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/19717/1
diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index cd5fe42..d369aed 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -160,11 +160,13 @@
{
const char *ext;
- ext = strrchr(str, '.');
- if (ext && ast_get_format_for_file_ext(ext + 1)) {
- ast_debug(3, "Found extension '%s' at end of string\n", ext);
- ast_copy_string(buffer, ext, capacity);
- return buffer;
+ if (str) {
+ ext = strrchr(str, '.');
+ if (ext && ast_get_format_for_file_ext(ext + 1)) {
+ ast_debug(3, "Found extension '%s' at end of string\n", ext);
+ ast_copy_string(buffer, ext, capacity);
+ return buffer;
+ }
}
return NULL;
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19717
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273
Gerrit-Change-Number: 19717
Gerrit-PatchSet: 1
Gerrit-Owner: Holger Hans Peter Freyther <automatic at freyther.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221216/20b9fe84/attachment-0001.html>
More information about the asterisk-code-review
mailing list