<p>Holger Hans Peter Freyther has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19717">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache: Do not crash when there is no extension<br><br>Do not crash when a URL has no path component. In this case the<br>ast_uri_path function will return NULL. Make the code cope with<br>str being NULL.<br><br>The below would crash<br>> media cache create http://google.com /tmp/foo.wav<br><br>Thread 1 "asterisk" received signal SIGSEGV, Segmentation fault.<br>0x0000ffff836616cc in strrchr () from /lib/aarch64-linux-gnu/libc.so.6<br>(gdb) bt<br> #0 0x0000ffff836616cc in strrchr () from /lib/aarch64-linux-gnu/libc.so.6<br> #1 0x0000ffff43d43a78 in file_extension_from_string (str=<optimized out>, buffer=buffer@entry=0xffffca9973c0 "",<br> capacity=capacity@entry=64) at res_http_media_cache.c:288<br> #2 0x0000ffff43d43bac in file_extension_from_url_path (bucket_file=bucket_file@entry=0x3bf96568,<br> buffer=buffer@entry=0xffffca9973c0 "", capacity=capacity@entry=64) at res_http_media_cache.c:378<br> #3 0x0000ffff43d43c74 in bucket_file_set_extension (bucket_file=bucket_file@entry=0x3bf96568) at res_http_media_cache.c:392<br> #4 0x0000ffff43d43d10 in bucket_file_run_curl (bucket_file=0x3bf96568) at res_http_media_cache.c:555<br> #5 0x0000ffff43d43f74 in bucket_http_wizard_create (sorcery=<optimized out>, data=<optimized out>, object=<optimized out>)<br> at res_http_media_cache.c:613<br> #6 0x0000000000487638 in bucket_file_wizard_create (sorcery=<optimized out>, data=<optimized out>, object=<optimized out>)<br> at bucket.c:191<br> #7 0x0000000000554408 in sorcery_wizard_create (object_wizard=object_wizard@entry=0x3b9f0718,<br> details=details@entry=0xffffca9974a8) at sorcery.c:2027<br> #8 0x0000000000559698 in ast_sorcery_create (sorcery=<optimized out>, object=object@entry=0x3bf96568) at sorcery.c:2077<br> #9 0x00000000004893a4 in ast_bucket_file_create (file=file@entry=0x3bf96568) at bucket.c:727<br> #10 0x00000000004f877c in ast_media_cache_create_or_update (uri=0x3bfa1103 "https://google.com",<br> file_path=0x3bfa1116 "/tmp/foo.wav", metadata=metadata@entry=0x0) at media_cache.c:335<br> #11 0x00000000004f88ec in media_cache_handle_create_item (e=<optimized out>, cmd=<optimized out>, a=0xffffca9976b8)<br> at media_cache.c:640<br><br>Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273<br>---<br>M res/res_http_media_cache.c<br>1 file changed, 46 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/19717/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index cd5fe42..d369aed 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -160,11 +160,13 @@</span><br><span> {</span><br><span> const char *ext;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ext = strrchr(str, '.');</span><br><span style="color: hsl(0, 100%, 40%);">- if (ext && ast_get_format_for_file_ext(ext + 1)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(3, "Found extension '%s' at end of string\n", ext);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_string(buffer, ext, capacity);</span><br><span style="color: hsl(0, 100%, 40%);">- return buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (str) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ext = strrchr(str, '.');</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ext && ast_get_format_for_file_ext(ext + 1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Found extension '%s' at end of string\n", ext);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(buffer, ext, capacity);</span><br><span style="color: hsl(120, 100%, 40%);">+ return buffer;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> return NULL;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19717">change 19717</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19717"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273 </div>
<div style="display:none"> Gerrit-Change-Number: 19717 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Holger Hans Peter Freyther <automatic@freyther.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>