<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19761">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">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
</div><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 as in this case the<br>ast_uri_path function will return NULL. Make the code cope with not<br>having a path.<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>ASTERISK-30375 #close<br><br>Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273<br>---<br>M res/res_http_media_cache.c<br>1 file changed, 49 insertions(+), 1 deletion(-)<br><br></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..b4c4c65 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -240,6 +240,7 @@</span><br><span> </span><br><span> static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *path;</span><br><span> struct ast_uri *uri;</span><br><span> </span><br><span> uri = ast_uri_parse(ast_sorcery_object_get_id(bucket_file));</span><br><span>@@ -249,8 +250,14 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ path = ast_uri_path(uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!path) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Just parse it as a string like before, but without the extra cruft */</span><br><span style="color: hsl(0, 100%, 40%);">- buffer = file_extension_from_string(ast_uri_path(uri), buffer, capacity);</span><br><span style="color: hsl(120, 100%, 40%);">+ buffer = file_extension_from_string(path, buffer, capacity);</span><br><span> ao2_cleanup(uri);</span><br><span> return buffer;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19761">change 19761</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/+/19761"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I6a9433688cb5d3d4be8758b7642d923bdde6c273 </div>
<div style="display:none"> Gerrit-Change-Number: 19761 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-CC: Holger Hans Peter Freyther <automatic@freyther.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>