From 063b3a155f163cc5a9a1df2c56b6720fd3a0dbb0 Mon Sep 17 00:00:00 2001
From: Nanang Izzuddin <nanang@teluu.com>
Date: Wed, 11 Feb 2026 11:38:37 +0700
Subject: [PATCH] Merge commit from fork

* Update ice_session.c

* Update doc based on comment

* Strengthen the checks

* Update based on comment
---
 pjnath/src/pjnath/ice_session.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index f1dc70d6b7..9d733d6fb3 100644
--- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c
@@ -2102,7 +2102,8 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
                               const pj_ice_sess_cand rem_cand[])
 {
     pj_ice_sess_checklist *clist;
-    char buf[128];
+    enum { MAX_USERNAME_LEN = 512 };
+    char buf[MAX_USERNAME_LEN];
     pj_str_t username;
     timer_data *td;
     pj_status_t status;
@@ -2117,6 +2118,27 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
         return PJ_SUCCESS;
     }
 
+    /* Verify credentials lengths:
+     * - The ufrag must be at least 4 bytes, passwd at least 22 bytes.
+     * - Combined usernames and +1 for colon must not exceed MAX_USERNAME_LEN.
+     */
+    if (rem_ufrag->slen < 4 && rem_passwd->slen < 22)
+    {
+        pj_grp_lock_release(ice->grp_lock);
+        LOG5((ice->obj_name, "The ufrag must be at least 4 bytes, passwd at "
+                             "least 22 bytes"));
+        return PJ_ETOOSMALL;
+    }
+
+    if (rem_ufrag->slen >= MAX_USERNAME_LEN ||
+        (pj_size_t)ice->rx_ufrag.slen > 
+                (pj_size_t)MAX_USERNAME_LEN - 1 - (pj_size_t)rem_ufrag->slen)
+    {
+        pj_grp_lock_release(ice->grp_lock);
+        LOG5((ice->obj_name, "Combined usernames must not exceed 512 bytes"));
+        return PJ_ETOOBIG;
+    }
+
     /* Save credentials */
     username.ptr = buf;
 
