]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_http_media_cache: Do not crash when there is no extension
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>
Fri, 16 Dec 2022 07:00:42 +0000 (15:00 +0800)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 4 Jan 2023 11:16:33 +0000 (05:16 -0600)
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@entry=0xffffca9973c0 "",
    capacity=capacity@entry=64) at res_http_media_cache.c:288
 #2  0x0000ffff43d43bac in file_extension_from_url_path (bucket_file=bucket_file@entry=0x3bf96568,
    buffer=buffer@entry=0xffffca9973c0 "", capacity=capacity@entry=64) at res_http_media_cache.c:378
 #3  0x0000ffff43d43c74 in bucket_file_set_extension (bucket_file=bucket_file@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@entry=0x3b9f0718,
    details=details@entry=0xffffca9974a8) at sorcery.c:2027
 #8  0x0000000000559698 in ast_sorcery_create (sorcery=<optimized out>, object=object@entry=0x3bf96568) at sorcery.c:2077
 #9  0x00000000004893a4 in ast_bucket_file_create (file=file@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@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

res/res_http_media_cache.c

index 0ad5ea8047cfae4f44b61e2655915f6cb8d140a1..dfafdc767fbdfef0f7c5dcd90a56d346907578d7 100644 (file)
@@ -245,6 +245,7 @@ static char *file_extension_from_content_type(struct ast_bucket_file *bucket_fil
 
 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));
@@ -254,8 +255,14 @@ static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, c
                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;
 }