aboutsummaryrefslogtreecommitdiffstats
path: root/main/udptl.c
diff options
context:
space:
mode:
authordvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-02 19:57:47 +0000
committerdvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-02 19:57:47 +0000
commit5886c3e0199fc776facdf18dfce178c0797f4c2b (patch)
tree25fa0a2d5c8707098edf93d2bdf291d560846b46 /main/udptl.c
parentbcf59acef4a16f32427b9d11d1f40976355c3675 (diff)
Fixes T38 crash with invalid FaxMaxDatagram field
AST-2010-001 git-svn-id: http://svn.digium.com/svn/asterisk/tags/1.6.0.22@244386 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/udptl.c')
-rw-r--r--main/udptl.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/main/udptl.c b/main/udptl.c
index 492a2de43..1e5df9ea3 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -91,6 +91,8 @@ static int udptlfecspan;
static int use_even_ports;
#define LOCAL_FAX_MAX_DATAGRAM 1400
+#define DEFAULT_FAX_MAX_DATAGRAM 400
+#define FAX_MAX_DATAGRAM_LIMIT 1400
#define MAX_FEC_ENTRIES 5
#define MAX_FEC_SPAN 5
@@ -854,9 +856,13 @@ void ast_udptl_set_error_correction_scheme(struct ast_udptl *udptl, enum ast_t38
void ast_udptl_set_local_max_ifp(struct ast_udptl *udptl, unsigned int max_ifp)
{
- udptl->local_max_ifp = max_ifp;
- /* reset calculated values so they'll be computed again */
- udptl->local_max_datagram = -1;
+ /* make sure max_ifp is a positive value since a cast will take place when
+ * when setting local_max_ifp */
+ if ((signed int) max_ifp > 0) {
+ udptl->local_max_ifp = max_ifp;
+ /* reset calculated values so they'll be computed again */
+ udptl->local_max_datagram = -1;
+ }
}
unsigned int ast_udptl_get_local_max_datagram(struct ast_udptl *udptl)
@@ -864,18 +870,30 @@ unsigned int ast_udptl_get_local_max_datagram(struct ast_udptl *udptl)
if (udptl->local_max_datagram == -1) {
calculate_local_max_datagram(udptl);
}
+
+ /* this function expects a unsigned value in return. */
+ if (udptl->local_max_datagram < 0) {
+ return 0;
+ }
return udptl->local_max_datagram;
}
void ast_udptl_set_far_max_datagram(struct ast_udptl *udptl, unsigned int max_datagram)
{
- udptl->far_max_datagram = max_datagram;
+ if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
+ udptl->far_max_datagram = DEFAULT_FAX_MAX_DATAGRAM;
+ } else {
+ udptl->far_max_datagram = max_datagram;
+ }
/* reset calculated values so they'll be computed again */
udptl->far_max_ifp = -1;
}
unsigned int ast_udptl_get_far_max_datagram(const struct ast_udptl *udptl)
{
+ if (udptl->far_max_datagram < 0) {
+ return 0;
+ }
return udptl->far_max_datagram;
}
@@ -884,6 +902,10 @@ unsigned int ast_udptl_get_far_max_ifp(struct ast_udptl *udptl)
if (udptl->far_max_ifp == -1) {
calculate_far_max_ifp(udptl);
}
+
+ if (udptl->far_max_ifp < 0) {
+ return 0;
+ }
return udptl->far_max_ifp;
}
@@ -1033,7 +1055,11 @@ int ast_udptl_write(struct ast_udptl *s, struct ast_frame *f)
unsigned int seq;
unsigned int len = f->datalen;
int res;
- uint8_t buf[s->far_max_datagram];
+ /* if no max datagram size is provided, use default value */
+ const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
+ uint8_t buf[bufsize];
+
+ memset(buf, 0, sizeof(buf));
/* If we have no peer, return immediately */
if (s->them.sin_addr.s_addr == INADDR_ANY)