webrtc_private: Check prefix of STUN/TURN server URL 08/279408/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 9 Aug 2022 02:22:57 +0000 (11:22 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 9 Aug 2022 02:24:09 +0000 (11:24 +0900)
Doxygen is also improved.

[Version] 0.3.197
[Issue Type] Improvement

Change-Id: Ia3d2b0991cdef41709cd2d5c19d8e0c82bf09a40
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_private.c

index 0cb403a3d43d159c16f6e44208bde46a2384bdda..3cc748c44d2fa09e32bfc0baf67edf6cc2288373 100644 (file)
@@ -1869,7 +1869,7 @@ int webrtc_media_source_unset_video_loopback(webrtc_h webrtc, unsigned int sourc
  * @since_tizen 6.5
  * @remarks Regarding STUN, refer to the RFC7064(https://tools.ietf.org/html/rfc7064).
  * @param[in] webrtc       WebRTC handle
- * @param[in] stun_server  The STUN server URL
+ * @param[in] stun_server  The STUN server URL of the form stun://host:port
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #WEBRTC_ERROR_NONE    Successful
index 023851e243ad2aaef1d5fd6e53ffd22f53b7145d..4a9966bc74e5450731adfb91a66e6245530340aa 100644 (file)
@@ -832,6 +832,7 @@ webrtc_gst_slot_s* _get_slot_by_id(GHashTable *slots, unsigned int id);
 int _add_no_target_ghostpad_to_slot(webrtc_gst_slot_s *slot, bool is_src, GstPad **new_pad);
 int _set_ghost_pad_target(GstPad *ghost_pad, GstElement *target_element, bool is_src);
 void _generate_dot(GstElement *pipeline, const gchar *name);
+bool _stun_url_has_valid_prefix(const char *url);
 gchar *_check_and_encode_turn_url(const char *url);
 
 #ifdef __cplusplus
index fd1b91e1998e1bd23bd148cec2119495d9cd35b9..1360924f359eb8bce2ccb2edc7ba767d51333593 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.196
+Version:    0.3.197
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 04bfd9daae3161f4109c3d9d389f33d774e39d1c..061cabf24cb0da8b80b94b126dc14e950977ba79 100644 (file)
@@ -954,6 +954,9 @@ int webrtc_set_stun_server(webrtc_h webrtc, const char *stun_server)
 
        RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE");
 
+       if (!_stun_url_has_valid_prefix(stun_server))
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+
        g_free(_webrtc->stun_server_url);
 
        /* FIXME: validate this url before setting */
@@ -1000,7 +1003,8 @@ int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server)
 
        RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE");
 
-       turn_url = _check_and_encode_turn_url(turn_server);
+       if (!(turn_url = _check_and_encode_turn_url(turn_server)))
+               return WEBRTC_ERROR_INVALID_PARAMETER;
 
        g_signal_emit_by_name(G_OBJECT(_webrtc->gst.webrtcbin), "add-turn-server", turn_url, &ret);
        if (!ret) {
index 13000e5935ee561b10499d86671056227f412a43..08f037765b841ea477992d2f99b0f0aa60b958ce 100644 (file)
@@ -141,12 +141,35 @@ void _generate_dot(GstElement *pipeline, const gchar *name)
 }
 //LCOV_EXCL_STOP
 
+bool _stun_url_has_valid_prefix(const char *url)
+{
+       if (!g_str_has_prefix(url, "stun://")) {
+               LOG_ERROR("STUN url[%s] must start with 'stun://'", url);
+               return false;
+       }
+
+       return true;
+}
+
+static bool __turn_url_has_valid_prefix(const char *url)
+{
+       if (!g_str_has_prefix(url, "turn://") && !g_str_has_prefix(url, "turns://")) {
+               LOG_ERROR("TURN url[%s] must have 'turn(s)://'", url);
+               return false;
+       }
+
+       return true;
+}
+
 gchar *_check_and_encode_turn_url(const char *url)
 {
        g_auto(GStrv) str_arr = g_strsplit(url, "@", 2);
        g_auto(GStrv) str_arr2 = g_strsplit(str_arr[0], ":", 0);
        g_autofree gchar *password = NULL;
 
+       if (!__turn_url_has_valid_prefix(url))
+               return NULL;
+
        if (g_strv_length(str_arr2) > 3) { /* NOTE: assume id has ':' character */
                password = g_uri_escape_string(str_arr2[3], NULL, FALSE);
                return g_strdup_printf("%s:%s%s%s:%s@%s",