Commit d61c6772 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix multiple buffer overflows arriving when to_string tmp buffer is too small.

optimize to_string mechanism.
parent 7afef88d
...@@ -124,6 +124,7 @@ struct _belle_sip_object_vptr{ ...@@ -124,6 +124,7 @@ struct _belle_sip_object_vptr{
belle_sip_object_destroy_t destroy; belle_sip_object_destroy_t destroy;
belle_sip_object_clone_t clone; belle_sip_object_clone_t clone;
belle_sip_object_marshal_t marshal; belle_sip_object_marshal_t marshal;
int tostring_bufsize_hint; /*optimization: you can suggest here the typical size for a to_string() result.*/
}; };
typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t; typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t;
...@@ -223,7 +224,7 @@ BELLESIP_EXPORT void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_t ...@@ -223,7 +224,7 @@ BELLESIP_EXPORT void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_t
* WHen the object is a sip header, uri or message, this is the textual representation of the header, uri or message. * WHen the object is a sip header, uri or message, this is the textual representation of the header, uri or message.
* This function internally calls belle_sip_object_marshal(). * This function internally calls belle_sip_object_marshal().
**/ **/
BELLESIP_EXPORT char* belle_sip_object_to_string(belle_sip_object_t* obj); BELLESIP_EXPORT char* belle_sip_object_to_string(void* obj);
/** /**
* Writes a string representation of the object into the supplied buffer. * Writes a string representation of the object into the supplied buffer.
......
...@@ -43,12 +43,15 @@ int belle_sdp_attribute_marshal(belle_sdp_attribute_t* attribute, char* buff,uns ...@@ -43,12 +43,15 @@ int belle_sdp_attribute_marshal(belle_sdp_attribute_t* attribute, char* buff,uns
,buff_size-current_offset ,buff_size-current_offset
,"a=%s" ,"a=%s"
,attribute->name); ,attribute->name);
if (current_offset>=buff_size) goto end;
if (attribute->value) { if (attribute->value) {
current_offset+=snprintf( buff+current_offset current_offset+=snprintf( buff+current_offset
,buff_size-current_offset ,buff_size-current_offset
,":%s" ,":%s"
,attribute->value); ,attribute->value);
if (current_offset>=buff_size) goto end;
} }
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SDP_NEW(attribute,belle_sip_object) BELLE_SDP_NEW(attribute,belle_sip_object)
...@@ -234,22 +237,27 @@ int belle_sdp_media_marshal(belle_sdp_media_t* media, char* buff,unsigned int of ...@@ -234,22 +237,27 @@ int belle_sdp_media_marshal(belle_sdp_media_t* media, char* buff,unsigned int of
,media->media_type ,media->media_type
,media->media_port ,media->media_port
); );
if (current_offset>=buff_size) goto end;
if (media->port_count>1) { if (media->port_count>1) {
current_offset+=snprintf(buff+current_offset current_offset+=snprintf(buff+current_offset
,buff_size-current_offset ,buff_size-current_offset
,"/%i" ,"/%i"
,media->port_count); ,media->port_count);
if (current_offset>=buff_size) goto end;
} }
current_offset+=snprintf( buff+current_offset current_offset+=snprintf( buff+current_offset
,buff_size-current_offset ,buff_size-current_offset
," %s" ," %s"
,media->protocol); ,media->protocol);
if (current_offset>=buff_size) goto end;
for(;list!=NULL;list=list->next){ for(;list!=NULL;list=list->next){
current_offset+=snprintf( buff+current_offset current_offset+=snprintf( buff+current_offset
,buff_size-current_offset ,buff_size-current_offset
," %li" ," %li"
,(long)list->data); ,(long)list->data);
if (current_offset>=buff_size) goto end;
} }
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SDP_NEW_WITH_CTR(media,belle_sip_object) BELLE_SDP_NEW_WITH_CTR(media,belle_sip_object)
...@@ -311,20 +319,27 @@ int belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_descri ...@@ -311,20 +319,27 @@ int belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_descri
// belle_sip_list_t* attributes; // belle_sip_list_t* attributes;
if (base_description->info) { if (base_description->info) {
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(base_description->info),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(base_description->info),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
if (base_description->connection) { if (base_description->connection) {
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(base_description->connection),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(base_description->connection),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
for(bandwidths=base_description->bandwidths;bandwidths!=NULL;bandwidths=bandwidths->next){ for(bandwidths=base_description->bandwidths;bandwidths!=NULL;bandwidths=bandwidths->next){
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(bandwidths->data),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(bandwidths->data),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
// for(attributes=base_description->attributes;attributes!=NULL;attributes=attributes->next){ // for(attributes=base_description->attributes;attributes!=NULL;attributes=attributes->next){
// current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size); // current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size);
// current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); // current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
// } // }
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -447,13 +462,19 @@ int belle_sdp_media_description_marshal(belle_sdp_media_description_t* media_des ...@@ -447,13 +462,19 @@ int belle_sdp_media_description_marshal(belle_sdp_media_description_t* media_des
unsigned int current_offset=offset; unsigned int current_offset=offset;
belle_sip_list_t* attributes; belle_sip_list_t* attributes;
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(media_description->media),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(media_description->media),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
current_offset+=belle_sdp_base_description_marshal(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),buff,current_offset,buff_size); current_offset+=belle_sdp_base_description_marshal(BELLE_SIP_CAST(media_description,belle_sdp_base_description_t),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
for(attributes=media_description->base_description.attributes;attributes!=NULL;attributes=attributes->next){ for(attributes=media_description->base_description.attributes;attributes!=NULL;attributes=attributes->next){
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SDP_NEW(media_description,belle_sdp_base_description) BELLE_SDP_NEW(media_description,belle_sdp_base_description)
...@@ -687,7 +708,7 @@ belle_sip_list_t* belle_sdp_media_description_build_mime_parameters(const belle_ ...@@ -687,7 +708,7 @@ belle_sip_list_t* belle_sdp_media_description_build_mime_parameters(const belle_
} }
return mime_parameter_list; return mime_parameter_list;
} }
#define MAX_FMTP_LENGH 64 #define MAX_FMTP_LENGH 512
void belle_sdp_media_description_append_values_from_mime_parameter(belle_sdp_media_description_t* media_description, const belle_sdp_mime_parameter_t* mime_parameter) { void belle_sdp_media_description_append_values_from_mime_parameter(belle_sdp_media_description_t* media_description, const belle_sdp_mime_parameter_t* mime_parameter) {
belle_sdp_media_t* media = belle_sdp_media_description_get_media(media_description); belle_sdp_media_t* media = belle_sdp_media_description_get_media(media_description);
...@@ -930,31 +951,44 @@ int belle_sdp_session_description_marshal(belle_sdp_session_description_t* sessi ...@@ -930,31 +951,44 @@ int belle_sdp_session_description_marshal(belle_sdp_session_description_t* sessi
belle_sip_list_t* attributes; belle_sip_list_t* attributes;
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->version),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->version),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->origin),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->origin),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->session_name),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(session_description->session_name),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
current_offset+=belle_sdp_base_description_marshal((belle_sdp_base_description_t*)(&session_description->base_description),buff,current_offset,buff_size); current_offset+=belle_sdp_base_description_marshal((belle_sdp_base_description_t*)(&session_description->base_description),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "t="); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "t=");
if (current_offset>=buff_size) goto end;
for(times=session_description->times;times!=NULL;times=times->next){ for(times=session_description->times;times!=NULL;times=times->next){
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(times->data),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(times->data),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
for(attributes=session_description->base_description.attributes;attributes!=NULL;attributes=attributes->next){ for(attributes=session_description->base_description.attributes;attributes!=NULL;attributes=attributes->next){
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n"); current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
if (current_offset>=buff_size) goto end;
} }
for(media_descriptions=session_description->media_descriptions;media_descriptions!=NULL;media_descriptions=media_descriptions->next){ for(media_descriptions=session_description->media_descriptions;media_descriptions!=NULL;media_descriptions=media_descriptions->next){
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(media_descriptions->data),buff,current_offset,buff_size); current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(media_descriptions->data),buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
} }
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SDP_NEW(session_description,belle_sdp_base_description) BELLE_SDP_NEW(session_description,belle_sdp_base_description)
......
...@@ -102,7 +102,8 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b ...@@ -102,7 +102,8 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b
/*1 display name*/ /*1 display name*/
unsigned int current_offset=offset; unsigned int current_offset=offset;
if (header->displayname) { if (header->displayname) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"\"%s\" ",header->displayname);; current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"\"%s\" ",header->displayname);
if (current_offset>=buff_size) goto end;
} }
if (header->uri) { if (header->uri) {
/*cases where < is required*/ /*cases where < is required*/
...@@ -111,6 +112,7 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b ...@@ -111,6 +112,7 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b
|| belle_sip_uri_get_header_names(header->uri) || belle_sip_uri_get_header_names(header->uri)
|| belle_sip_parameters_get_parameter_names(&header->base)) { || belle_sip_parameters_get_parameter_names(&header->base)) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","<"); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","<");
if (current_offset>=buff_size) goto end;
} }
current_offset+=belle_sip_uri_marshal(header->uri,buff,current_offset,buff_size); current_offset+=belle_sip_uri_marshal(header->uri,buff,current_offset,buff_size);
if (header->displayname if (header->displayname
...@@ -118,9 +120,12 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b ...@@ -118,9 +120,12 @@ int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* b
|| belle_sip_uri_get_header_names(header->uri) || belle_sip_uri_get_header_names(header->uri)
|| belle_sip_parameters_get_parameter_names(&header->base)) { || belle_sip_parameters_get_parameter_names(&header->base)) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",">"); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",">");
if (current_offset>=buff_size) goto end;
} }
} }
current_offset+=belle_sip_parameters_marshal(&header->base,buff,current_offset,buff_size); current_offset+=belle_sip_parameters_marshal(&header->base,buff,current_offset,buff_size);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -174,7 +179,10 @@ static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) { ...@@ -174,7 +179,10 @@ static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) {
int belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",allow->method); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",allow->method);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -211,6 +219,8 @@ int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* ...@@ -211,6 +219,8 @@ int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char*
} else { } else {
current_offset+=belle_sip_header_address_marshal(&contact->address, buff,current_offset, buff_size); current_offset+=belle_sip_header_address_marshal(&contact->address, buff,current_offset, buff_size);
} }
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SIP_NEW_HEADER(header_contact,header_address,BELLE_SIP_CONTACT) BELLE_SIP_NEW_HEADER(header_contact,header_address,BELLE_SIP_CONTACT)
...@@ -260,7 +270,10 @@ unsigned int belle_sip_header_contact_not_equals(const belle_sip_header_contact_ ...@@ -260,7 +270,10 @@ unsigned int belle_sip_header_contact_not_equals(const belle_sip_header_contact_
#define BELLE_SIP_FROM_LIKE_MARSHAL(header) \ #define BELLE_SIP_FROM_LIKE_MARSHAL(header) \
unsigned int current_offset=offset; \ unsigned int current_offset=offset; \
current_offset+=belle_sip_##header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\ current_offset+=belle_sip_##header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
if (current_offset>=buff_size) goto end;\
current_offset+=belle_sip_header_address_marshal(&header->address, buff,current_offset, buff_size); \ current_offset+=belle_sip_header_address_marshal(&header->address, buff,current_offset, buff_size); \
if (current_offset>=buff_size) goto end;\
end:\
return current_offset-offset; return current_offset-offset;
struct _belle_sip_header_from { struct _belle_sip_header_from {
...@@ -392,7 +405,9 @@ int belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agen ...@@ -392,7 +405,9 @@ int belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agen
,buff_size-current_offset ,buff_size-current_offset
,list==user_agent->products ? "%s" : " %s" ,list==user_agent->products ? "%s" : " %s"
,(const char *)list->data); ,(const char *)list->data);
if (current_offset>=buff_size) goto end;
} }
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -460,7 +475,9 @@ static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_ ...@@ -460,7 +475,9 @@ static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_
int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",via->protocol,via->transport); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",via->protocol,via->transport);
if (current_offset>=buff_size) goto end;
if (via->host) { if (via->host) {
if (strchr(via->host,':')) { /*ipv6*/ if (strchr(via->host,':')) { /*ipv6*/
...@@ -468,18 +485,24 @@ int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigne ...@@ -468,18 +485,24 @@ int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigne
} else { } else {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",via->host); current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",via->host);
} }
if (current_offset>=buff_size) goto end;
} else { } else {
belle_sip_warning("no host found in this via"); belle_sip_warning("no host found in this via");
} }
if (via->port > 0) { if (via->port > 0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,":%i",via->port); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,":%i",via->port);
if (current_offset>=buff_size) goto end;
} }
if (via->received) { if (via->received) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,";received=%s",via->received); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,";received=%s",via->received);
if (current_offset>=buff_size) goto end;
} }
current_offset+=belle_sip_parameters_marshal(&via->params_list, buff,current_offset, buff_size); current_offset+=belle_sip_parameters_marshal(&via->params_list, buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -576,7 +599,10 @@ static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,c ...@@ -576,7 +599,10 @@ static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,c
int belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",call_id->call_id); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",call_id->call_id);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
unsigned int belle_sip_header_call_id_equals(const belle_sip_header_call_id_t* a,const belle_sip_header_call_id_t* b) { unsigned int belle_sip_header_call_id_equals(const belle_sip_header_call_id_t* a,const belle_sip_header_call_id_t* b) {
...@@ -606,7 +632,10 @@ static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const bel ...@@ -606,7 +632,10 @@ static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const bel
int belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i %s",cseq->seq_number,cseq->method); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i %s",cseq->seq_number,cseq->method);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
belle_sip_header_cseq_t * belle_sip_header_cseq_create(unsigned int number, const char *method){ belle_sip_header_cseq_t * belle_sip_header_cseq_create(unsigned int number, const char *method){
...@@ -641,8 +670,13 @@ static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t* ...@@ -641,8 +670,13 @@ static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t*
int belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",content_type->type, content_type->subtype); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",content_type->type, content_type->subtype);
if (current_offset>=buff_size) goto end;
current_offset+=belle_sip_parameters_marshal(&content_type->params_list, buff,current_offset, buff_size); current_offset+=belle_sip_parameters_marshal(&content_type->params_list, buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SIP_NEW_HEADER(header_content_type,parameters,BELLE_SIP_CONTENT_TYPE) BELLE_SIP_NEW_HEADER(header_content_type,parameters,BELLE_SIP_CONTENT_TYPE)
...@@ -737,7 +771,10 @@ static void belle_sip_header_content_length_clone(belle_sip_header_content_lengt ...@@ -737,7 +771,10 @@ static void belle_sip_header_content_length_clone(belle_sip_header_content_lengt
int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SIP_NEW_HEADER(header_content_length,header,BELLE_SIP_CONTENT_LENGTH) BELLE_SIP_NEW_HEADER(header_content_length,header,BELLE_SIP_CONTENT_LENGTH)
...@@ -769,7 +806,10 @@ static void belle_sip_header_expires_clone(belle_sip_header_expires_t* expires, ...@@ -769,7 +806,10 @@ static void belle_sip_header_expires_clone(belle_sip_header_expires_t* expires,
int belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(expires), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(expires), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",expires->expires); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",expires->expires);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
BELLE_SIP_NEW_HEADER(header_expires,header,BELLE_SIP_EXPIRES) BELLE_SIP_NEW_HEADER(header_expires,header,BELLE_SIP_EXPIRES)
...@@ -799,7 +839,10 @@ static void belle_sip_header_extension_clone(belle_sip_header_extension_t* exten ...@@ -799,7 +839,10 @@ static void belle_sip_header_extension_clone(belle_sip_header_extension_t* exten
int belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff,unsigned int offset,unsigned int buff_size) { int belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset; unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(extension), buff,current_offset, buff_size); current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(extension), buff,current_offset, buff_size);
if (current_offset>=buff_size) goto end;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",extension->value); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",extension->value);
if (current_offset>=buff_size) goto end;
end:
return current_offset-offset; return current_offset-offset;
} }
...@@ -875,35 +918,42 @@ GET_SET_STRING(belle_sip_header_extension,value); ...@@ -875,35 +918,42 @@ GET_SET_STRING(belle_sip_header_extension,value);
char* border=" ";\ char* border=" ";\
const belle_sip_list_t* list;\ const belle_sip_list_t* list;\
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\ current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
if (current_offset>=buff_size) goto end;\
list=belle_sip_parameters_get_parameters(&header->params_list);\ list=belle_sip_parameters_get_parameters(&header->params_list);\
if (header->scheme) { \ if (header->scheme) { \
current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",header->scheme);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",header->scheme);\
if (current_offset>=buff_size) goto end;\
} else { \ } else { \
belle_sip_error("missing mandatory scheme"); \ belle_sip_error("missing mandatory scheme"); \
} \ } \
for(;list!=NULL;list=list->next){\ for(;list!=NULL;list=list->next){\
belle_sip_param_pair_t* container = list->data;\ belle_sip_param_pair_t* container = list->data;\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s%s=%s",border, container->name,container->value);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s%s=%s",border, container->name,container->value);\
if (current_offset>=buff_size) goto end;\
border=", ";\ border=", ";\
}\ }\
if (header->realm) {\ if (header->realm) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%srealm=\"%s\"",border,header->realm);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%srealm=\"%s\"",border,header->realm);\
if (current_offset>=buff_size) goto end;\
border=", ";\ border=", ";\
}\ }\
if (header->nonce) {\ if (header->nonce) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snonce=\"%s\"",border,header->nonce);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snonce=\"%s\"",border,header->nonce);\
if (current_offset>=buff_size) goto end;\
border=", ";\ border=", ";\
}\ }\
if (header->algorithm) {\ if (header->algorithm) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,header->algorithm);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,header->algorithm);\
if (current_offset>=buff_size) goto end;\
border=", ";\ border=", ";\
}\ }\
if (header->opaque) {\ if (header->opaque) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sopaque=\"%s\"",border,header->opaque);\ current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sopaque=\"%s\"",border,header->opaque);\
if (current_offset>=buff_size) goto end;\
border=", ";\ border=", ";\
} }
struct _belle_sip_header_authorization { struct _belle_sip_header_authorization {
AUTH_BASE AUTH_BASE
const char* username; const char* username;
belle_sip_uri_t* uri; belle_sip_uri_t* uri;
...@@ -911,7 +961,6 @@ GET_SET_STRING(belle_sip_header_extension,value); ...@@ -911,7 +961,6 @@ GET_SET_STRING(belle_sip_header_extension,value);
const char* cnonce; const char* cnonce;
int nonce_count; int nonce_count;
const char* qop; const char* qop;