Skip to content

Commit a9e45e8

Browse files
committed
mid_registrar: Configurable max username/domain/AoR lengths
Fixes OpenSIPS#1964
1 parent 6c9c6ef commit a9e45e8

File tree

7 files changed

+73
-16
lines changed

7 files changed

+73
-16
lines changed

lib/reg/config.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define CALLID_MAX_SIZE 255
3333
#define UA_MAX_SIZE 255
3434

35+
#define MAX_AOR_LEN 256
36+
3537
#define PATH_MODE_STRICT 2
3638
#define PATH_MODE_LAZY 1
3739
#define PATH_MODE_OFF 0

modules/mid_registrar/doc/mid_registrar_admin.xml

+50
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ modparam("mid_registrar", "case_sensitive", 0)
653653
</programlisting>
654654
</example>
655655
</section>
656+
656657
<section id="param_max_contacts" xreflabel="max_contacts">
657658
<title><varname>max_contacts</varname> (integer)</title>
658659
<para>
@@ -675,6 +676,55 @@ modparam("mid_registrar", "max_contacts", 10)
675676
</programlisting>
676677
</example>
677678
</section>
679+
680+
<section id="param_max_username_len" xreflabel="max_username_len">
681+
<title><varname>max_username_len</varname> (integer)</title>
682+
<para>
683+
The maximum length of the "username" part of an Address-of-Record SIP URI.
684+
</para>
685+
<para>
686+
Default value is <emphasis role='bold'>64</emphasis>.
687+
</para>
688+
<example>
689+
<title>Setting the <emphasis>max_username_len</emphasis> module parameter</title>
690+
<programlisting format="linespecific">
691+
modparam("mid_registrar", "max_username_len", 128)
692+
</programlisting>
693+
</example>
694+
</section>
695+
696+
<section id="param_max_domain_len" xreflabel="max_domain_len">
697+
<title><varname>max_domain_len</varname> (integer)</title>
698+
<para>
699+
The maximum length of the "domain" part of an Address-of-Record SIP URI.
700+
</para>
701+
<para>
702+
Default value is <emphasis role='bold'>64</emphasis>.
703+
</para>
704+
<example>
705+
<title>Setting the <emphasis>max_domain_len</emphasis> module parameter</title>
706+
<programlisting format="linespecific">
707+
modparam("mid_registrar", "max_domain_len", 128)
708+
</programlisting>
709+
</example>
710+
</section>
711+
712+
<section id="param_max_aor_len" xreflabel="max_aor_len">
713+
<title><varname>max_aor_len</varname> (integer)</title>
714+
<para>
715+
The maximum length of an Address-of-Record SIP URI.
716+
</para>
717+
<para>
718+
Default value is <emphasis role='bold'>256</emphasis>.
719+
</para>
720+
<example>
721+
<title>Setting the <emphasis>max_aor_len</emphasis> module parameter</title>
722+
<programlisting format="linespecific">
723+
modparam("mid_registrar", "max_aor_len", 512)
724+
</programlisting>
725+
</example>
726+
</section>
727+
678728
<section id="param_retry_after" xreflabel="retry_after">
679729
<title><varname>retry_after</varname> (integer)</title>
680730
<para>

modules/mid_registrar/mid_registrar.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "ulcb.h"
4545

4646
#include "../../lib/reg/rerrno.h"
47+
#include "../../lib/reg/config.h"
4748
#include "../../lib/reg/sip_msg.h"
4849
#include "../../lib/reg/regtime.h"
4950

@@ -76,6 +77,9 @@ int max_expires = 3600;
7677

7778
int max_contacts = 0; /*!< Maximum number of contacts per AOR
7879
(0=no checking) */
80+
int max_username_len = USERNAME_MAX_SIZE;
81+
int max_domain_len = DOMAIN_MAX_SIZE;
82+
int max_aor_len = MAX_AOR_LEN;
7983
int retry_after = 0; /*!< The value of Retry-After HF in 5xx replies */
8084

8185
qvalue_t default_q = Q_UNSPECIFIED; /*!< Default q value multiplied by 1000 */
@@ -106,8 +110,7 @@ str rcv_param = str_init(RCV_NAME);
106110
int case_sensitive = 1; /*!< If set to 0, username in aor will be case insensitive */
107111
str gruu_secret = {0,0};
108112
int disable_gruu = 1;
109-
char* realm_pref = "";
110-
str realm_prefix;
113+
str realm_prefix = str_init("");
111114
int reg_use_domain = 0;
112115

113116
static int mod_init(void);
@@ -155,11 +158,14 @@ static param_export_t mod_params[] = {
155158
{ "max_expires", INT_PARAM, &max_expires },
156159
{ "default_q", INT_PARAM, &default_q },
157160
{ "tcp_persistent_flag", STR_PARAM, &tcp_persistent_flag_s },
158-
{ "realm_prefix", STR_PARAM, &realm_pref },
161+
{ "realm_prefix", STR_PARAM, &realm_prefix.s },
159162
{ "case_sensitive", INT_PARAM, &case_sensitive },
160163
{ "received_avp", STR_PARAM, &rcv_avp_param },
161164
{ "received_param", STR_PARAM, &rcv_param.s },
162165
{ "max_contacts", INT_PARAM, &max_contacts },
166+
{ "max_username_len", INT_PARAM, &max_username_len },
167+
{ "max_domain_len", INT_PARAM, &max_domain_len },
168+
{ "max_aor_len", INT_PARAM, &max_aor_len },
163169
{ "retry_after", INT_PARAM, &retry_after },
164170
{ "gruu_secret", STR_PARAM, &gruu_secret.s },
165171
{ "disable_gruu", INT_PARAM, &disable_gruu },
@@ -317,8 +323,7 @@ static int mod_init(void)
317323
return -1;
318324
}
319325

320-
realm_prefix.s = realm_pref;
321-
realm_prefix.len = strlen(realm_pref);
326+
realm_prefix.len = strlen(realm_prefix.s);
322327

323328
if (gruu_secret.s)
324329
gruu_secret.len = strlen(gruu_secret.s);

modules/mid_registrar/mid_registrar.h

+5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ extern struct sig_binds sig_api;
127127
extern int default_expires;
128128
extern int min_expires;
129129
extern int max_expires;
130+
130131
extern int max_contacts;
132+
extern int max_username_len;
133+
extern int max_domain_len;
134+
extern int max_aor_len;
135+
131136
extern int retry_after;
132137
extern unsigned int outgoing_expires;
133138

modules/mid_registrar/save.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ static struct {
7070
int data_len;
7171
} contact = {0, 0, 0};
7272

73-
#define MAX_AOR_LEN 256
74-
7573
#define MSG_200 "OK"
7674
#define MSG_400 "Bad Request"
7775
#define MSG_420 "Bad Extension"
@@ -2092,8 +2090,7 @@ int send_reply(struct sip_msg* _m, unsigned int _flags)
20922090

20932091
int extract_aor(str* _uri, str* _a,str *sip_instance,str *call_id)
20942092
{
2095-
static char aor_buf[MAX_AOR_LEN];
2096-
memset(aor_buf, 0, MAX_AOR_LEN);
2093+
char aor_buf[max_aor_len + 1];
20972094

20982095
str tmp;
20992096
struct sip_uri puri;
@@ -2183,9 +2180,9 @@ int extract_aor(str* _uri, str* _a,str *sip_instance,str *call_id)
21832180
}
21842181
}
21852182

2186-
if ( (puri.user.len + puri.host.len + 1) > MAX_AOR_LEN
2187-
|| puri.user.len > USERNAME_MAX_SIZE
2188-
|| puri.host.len > DOMAIN_MAX_SIZE ) {
2183+
if ( (puri.user.len + puri.host.len + 1) > max_aor_len
2184+
|| puri.user.len > max_username_len
2185+
|| puri.host.len > max_domain_len ) {
21892186
rerrno = R_AOR_LEN;
21902187
LM_ERR("Address Of Record too long\n");
21912188
return -2;
@@ -2217,6 +2214,8 @@ int extract_aor(str* _uri, str* _a,str *sip_instance,str *call_id)
22172214
}
22182215
}
22192216

2217+
_a->s[_a->len] = '\0';
2218+
22202219
if (case_sensitive && user_len) {
22212220
tmp.s = _a->s + user_len + 1;
22222221
tmp.len = _a->s + _a->len - tmp.s;

modules/mid_registrar/save.h

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848

4949
#define CONTACT_MAX_SIZE 255
5050
#define RECEIVED_MAX_SIZE 255
51-
#define USERNAME_MAX_SIZE 64
52-
#define DOMAIN_MAX_SIZE 64
5351
#define CALLID_MAX_SIZE 255
5452
#define UA_MAX_SIZE 255
5553

modules/registrar/common.c

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include "common.h"
4646

4747

48-
#define MAX_AOR_LEN 256
49-
5048
#define TEMP_GRUU "tgruu."
5149
#define TEMP_GRUU_SIZE (sizeof(TEMP_GRUU)-1)
5250

0 commit comments

Comments
 (0)