Skip to content

Commit

Permalink
Fixed #2209: Insufficient variable storage to contain Expires header …
Browse files Browse the repository at this point in the history
…field/ parameter

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@6035 74dad513-b988-da41-8d7b-12977e46ad98
  • Loading branch information
sauwming committed Jul 1, 2019
1 parent 2c5dc72 commit 3f58d4d
Show file tree
Hide file tree
Showing 26 changed files with 140 additions and 105 deletions.
4 changes: 2 additions & 2 deletions pjsip-apps/src/pjsua/pjsua_app.c
Expand Up @@ -1063,9 +1063,9 @@ static void simple_registrar(pjsip_rx_data *rdata)
while (h != &rdata->msg_info.msg->hdr) {
if (h->type == PJSIP_H_CONTACT) {
const pjsip_contact_hdr *c = (const pjsip_contact_hdr*)h;
int e = c->expires;
unsigned e = c->expires;

if (e < 0) {
if (e != PJSIP_EXPIRES_NOT_SPECIFIED) {
if (exp)
e = exp->ivalue;
else
Expand Down
2 changes: 1 addition & 1 deletion pjsip-apps/src/samples/footprint.c
Expand Up @@ -403,7 +403,7 @@ int dummy_function()
pjsip_evsub_terminate(NULL, PJ_FALSE);
pjsip_evsub_get_state(NULL);
pjsip_evsub_get_state_name(NULL);
pjsip_evsub_initiate(NULL, NULL, -1, NULL);
pjsip_evsub_initiate(NULL, NULL, PJSIP_EXPIRES_NOT_SPECIFIED, NULL);
pjsip_evsub_accept(NULL, NULL, 200, NULL);
pjsip_evsub_notify(NULL, PJSIP_EVSUB_STATE_ACTIVE, NULL, NULL, NULL);
pjsip_evsub_current_notify(NULL, NULL);
Expand Down
4 changes: 2 additions & 2 deletions pjsip-apps/src/samples/sipecho.c
Expand Up @@ -434,7 +434,7 @@ static pj_bool_t on_rx_request( pjsip_rx_data *rdata )
/* Let me be a registrar! */
pjsip_hdr hdr_list, *h;
pjsip_msg *msg;
int expires = -1;
unsigned expires = PJSIP_EXPIRES_NOT_SPECIFIED;

pj_list_init(&hdr_list);
msg = rdata->msg_info.msg;
Expand All @@ -444,7 +444,7 @@ static pj_bool_t on_rx_request( pjsip_rx_data *rdata )
pj_list_push_back(&hdr_list, pjsip_hdr_clone(rdata->tp_info.pool, h));
PJ_LOG(3,(THIS_FILE, " Expires=%d", expires));
}
if (expires != 0) {
if (expires != 0 && expires != PJSIP_EXPIRES_NOT_SPECIFIED) {
h = (pjsip_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
if (h)
pj_list_push_back(&hdr_list, pjsip_hdr_clone(rdata->tp_info.pool, h));
Expand Down
6 changes: 3 additions & 3 deletions pjsip/include/pjsip-simple/evsub.h
Expand Up @@ -363,15 +363,15 @@ PJ_DECL(const pj_str_t*) pjsip_evsub_get_termination_reason(pjsip_evsub *sub);
* SUBSCRIBE will be used.
* @param expires Subscription expiration. If the value is set to zero,
* this will request unsubscription. If the value is
* negative, default expiration as defined by the package
* will be used.
* PJSIP_EXPIRES_NOT_SPECIFIED, default expiration
* as defined by the package will be used.
* @param p_tdata Pointer to receive the request.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub,
const pjsip_method *method,
pj_int32_t expires,
pj_uint32_t expires,
pjsip_tx_data **p_tdata);


Expand Down
3 changes: 2 additions & 1 deletion pjsip/include/pjsip-simple/evsub_msg.h
Expand Up @@ -88,7 +88,8 @@ typedef struct pjsip_sub_state_hdr

pj_str_t sub_state; /**< Subscription state. */
pj_str_t reason_param; /**< Optional termination reason. */
int expires_param; /**< Expires param, or -1. */
unsigned expires_param; /**< Expires param, or
PJSIP_EXPIRES_NOT_SPECIFIED. */
int retry_after; /**< Retry after param, or -1. */
pjsip_param other_param; /**< Other parameters. */
} pjsip_sub_state_hdr;
Expand Down
6 changes: 4 additions & 2 deletions pjsip/include/pjsip-simple/mwi.h
Expand Up @@ -121,13 +121,15 @@ PJ_DECL(pj_status_t) pjsip_mwi_terminate( pjsip_evsub *sub,
*
* @param sub Client subscription instance.
* @param expires Subscription expiration. If the value is set to zero,
* this will request unsubscription.
* this will request unsubscription. If the value is
* PJSIP_EXPIRES_NOT_SPECIFIED, default expiration
* as defined by the package will be used.
* @param p_tdata Pointer to receive the request.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjsip_mwi_initiate( pjsip_evsub *sub,
pj_int32_t expires,
pj_uint32_t expires,
pjsip_tx_data **p_tdata);

/**
Expand Down
6 changes: 4 additions & 2 deletions pjsip/include/pjsip-simple/presence.h
Expand Up @@ -171,13 +171,15 @@ PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub,
*
* @param sub Client subscription instance.
* @param expires Subscription expiration. If the value is set to zero,
* this will request unsubscription.
* this will request unsubscription. If the value is
* PJSIP_EXPIRES_NOT_SPECIFIED, default expiration
* as defined by the package will be used.
* @param p_tdata Pointer to receive the request.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub,
pj_int32_t expires,
pj_uint32_t expires,
pjsip_tx_data **p_tdata);


Expand Down
8 changes: 5 additions & 3 deletions pjsip/include/pjsip-simple/publish.h
Expand Up @@ -97,9 +97,11 @@ struct pjsip_publishc_cbparam
int code; /**< SIP status code received. */
pj_str_t reason; /**< SIP reason phrase received. */
pjsip_rx_data *rdata; /**< The complete received response. */
int expiration;/**< Next expiration interval. If the
value is -1, it means the session
will not renew itself. */
unsigned expiration;/**< Next expiration interval. If the
value is
PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED,
it means the session will not renew
itself. */
};


Expand Down
10 changes: 6 additions & 4 deletions pjsip/include/pjsip-ua/sip_regc.h
Expand Up @@ -51,7 +51,7 @@ typedef struct pjsip_regc pjsip_regc;
#define PJSIP_REGC_MAX_CONTACT 10

/** Expiration not specified. */
#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
#define PJSIP_REGC_EXPIRATION_NOT_SPECIFIED PJSIP_EXPIRES_NOT_SPECIFIED

/** Buffer to hold all contacts. */
#define PJSIP_REGC_CONTACT_BUF_SIZE 512
Expand All @@ -74,7 +74,9 @@ struct pjsip_regc_cbparam
int code; /**< SIP status code received. */
pj_str_t reason; /**< SIP reason phrase received. */
pjsip_rx_data *rdata; /**< The complete received response. */
int expiration;/**< Next expiration interval. */
unsigned expiration;/**< Next expiration interval,
PJSIP_REGC_EXPIRATION_NOT_SPECIFIED
if not specified. */
int contact_cnt;/**<Number of contacts in response. */
pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; /**< Contacts. */
pj_bool_t is_unreg; /**< Expire header, if any, set to zero?*/
Expand Down Expand Up @@ -109,8 +111,8 @@ struct pjsip_regc_info
pj_str_t client_uri; /**< Client URI (From header). */
pj_bool_t is_busy; /**< Have pending transaction? */
pj_bool_t auto_reg; /**< Will register automatically? */
int interval; /**< Registration interval (seconds). */
int next_reg; /**< Time until next registration (seconds). */
unsigned interval; /**< Registration interval (seconds). */
unsigned next_reg; /**< Time until next registration (seconds). */
pjsip_transport *transport; /**< Last transport used. */
};

Expand Down
37 changes: 23 additions & 14 deletions pjsip/include/pjsip/sip_msg.h
Expand Up @@ -1070,7 +1070,7 @@ typedef struct pjsip_generic_int_hdr
/** Standard header field. */
PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr);
/** ivalue */
pj_int32_t ivalue;
pj_uint32_t ivalue;
} pjsip_generic_int_hdr;


Expand All @@ -1087,7 +1087,7 @@ typedef struct pjsip_generic_int_hdr
*/
PJ_DECL(pjsip_generic_int_hdr*) pjsip_generic_int_hdr_create( pj_pool_t *pool,
const pj_str_t *hname,
int hvalue );
unsigned hvalue );


/**
Expand All @@ -1110,7 +1110,7 @@ PJ_DECL(pjsip_generic_int_hdr*) pjsip_generic_int_hdr_create( pj_pool_t *pool,
PJ_DECL(pjsip_generic_int_hdr*) pjsip_generic_int_hdr_init( pj_pool_t *pool,
void *mem,
const pj_str_t *hname,
int value );
unsigned value );

/* **************************************************************************/

Expand Down Expand Up @@ -1349,6 +1349,10 @@ PJ_DECL(pjsip_cseq_hdr*) pjsip_cseq_hdr_init( pj_pool_t *pool,
void *mem );

/* **************************************************************************/

/** Expires not specified. */
#define PJSIP_EXPIRES_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)

/**
* Contact header.
* In this library, contact header only contains single URI. If a message has
Expand All @@ -1358,11 +1362,16 @@ PJ_DECL(pjsip_cseq_hdr*) pjsip_cseq_hdr_init( pj_pool_t *pool,
typedef struct pjsip_contact_hdr
{
PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr);
int star; /**< The contact contains only a '*' character */
pjsip_uri *uri; /**< URI in the contact. */
int q1000; /**< The "q" value times 1000 (to avoid float) */
pj_int32_t expires; /**< Expires parameter, otherwise -1 if not present. */
pjsip_param other_param; /**< Other parameters, concatenated in a single string. */
int star; /**< The contact contains only a '*'
character */
pjsip_uri *uri; /**< URI in the contact. */
int q1000; /**< The "q" value times 1000
(to avoid float) */
pj_uint32_t expires; /**< Expires parameter, otherwise
PJSIP_EXPIRES_NOT_SPECIFIED
if not present. */
pjsip_param other_param; /**< Other parameters, concatenated in
a single string. */
} pjsip_contact_hdr;


Expand Down Expand Up @@ -1441,7 +1450,7 @@ typedef pjsip_generic_int_hdr pjsip_expires_hdr;
* @return A new Expires header.
*/
PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_create( pj_pool_t *pool,
int value);
unsigned value);

/**
* Initialize a preallocated memory with the header structure. This function
Expand All @@ -1460,7 +1469,7 @@ PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_create( pj_pool_t *pool,
*/
PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_init( pj_pool_t *pool,
void *mem,
int value );
unsigned value );



Expand Down Expand Up @@ -1564,7 +1573,7 @@ typedef pjsip_generic_int_hdr pjsip_max_fwd_hdr;
* @return New Max-Forwards header instance.
*/
PJ_DECL(pjsip_max_fwd_hdr*)
pjsip_max_fwd_hdr_create(pj_pool_t *pool, int value);
pjsip_max_fwd_hdr_create(pj_pool_t *pool, unsigned value);


/**
Expand All @@ -1583,7 +1592,7 @@ pjsip_max_fwd_hdr_create(pj_pool_t *pool, int value);
* location as the mem argument.
*/
PJ_DECL(pjsip_max_fwd_hdr*)
pjsip_max_fwd_hdr_init( pj_pool_t *pool, void *mem, int value );
pjsip_max_fwd_hdr_init( pj_pool_t *pool, void *mem, unsigned value );


/* **************************************************************************/
Expand All @@ -1601,7 +1610,7 @@ typedef pjsip_generic_int_hdr pjsip_min_expires_hdr;
* @return New Min-Expires header instance.
*/
PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_create(pj_pool_t *pool,
int value);
unsigned value);


/**
Expand All @@ -1621,7 +1630,7 @@ PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_create(pj_pool_t *pool,
*/
PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_init( pj_pool_t *pool,
void *mem,
int value );
unsigned value );


/* **************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion pjsip/include/pjsip/sip_parser.h
Expand Up @@ -52,7 +52,7 @@ PJ_BEGIN_DECL
#define PJSIP_MIN_Q1000 0
#define PJSIP_MAX_Q1000 PJ_MAXINT32 / 1000
#define PJSIP_MIN_EXPIRES 0
#define PJSIP_MAX_EXPIRES PJ_MAXINT32
#define PJSIP_MAX_EXPIRES ((pj_uint32_t)0xFFFFFFFFUL)
#define PJSIP_MIN_CSEQ 0
#define PJSIP_MAX_CSEQ PJ_MAXINT32
#define PJSIP_MIN_RETRY_AFTER 0
Expand Down
5 changes: 3 additions & 2 deletions pjsip/include/pjsua-lib/pjsua.h
Expand Up @@ -4176,9 +4176,10 @@ typedef struct pjsua_acc_info
pj_bool_t has_registration;

/**
* An up to date expiration interval for account registration session.
* An up to date expiration interval for account registration session,
* PJSIP_EXPIRES_NOT_SPECIFIED if the account doesn't have reg session.
*/
int expires;
unsigned expires;

/**
* Last registration status code. If status code is zero, the account
Expand Down
4 changes: 3 additions & 1 deletion pjsip/include/pjsua-lib/pjsua_internal.h
Expand Up @@ -218,7 +218,9 @@ struct pjsua_srv_pres
char *remote; /**< Remote URI. */
int acc_id; /**< Account ID. */
pjsip_dialog *dlg; /**< Dialog. */
int expires; /**< "expires" value in the request. */
unsigned expires; /**< "expires" value in the request,
PJSIP_EXPIRES_NOT_SPECIFIED
if not present. */
};

/**
Expand Down
4 changes: 2 additions & 2 deletions pjsip/include/pjsua2/account.hpp
Expand Up @@ -1281,7 +1281,7 @@ struct AccountInfo
/**
* An up to date expiration interval for account registration session.
*/
int regExpiresSec;
unsigned regExpiresSec;

/**
* Last registration status code. If status code is zero, the account
Expand Down Expand Up @@ -1373,7 +1373,7 @@ struct OnRegStateParam
/**
* Next expiration interval.
*/
int expiration;
unsigned expiration;
};

/**
Expand Down
15 changes: 8 additions & 7 deletions pjsip/src/pjsip-simple/evsub.c
Expand Up @@ -499,7 +499,7 @@ static void update_expires( pjsip_evsub *sub, pj_uint32_t interval )
* Schedule timer.
*/
static void set_timer( pjsip_evsub *sub, int timer_id,
pj_int32_t seconds)
pj_uint32_t seconds)
{
if (sub->timer.id != TIMER_TYPE_NONE) {
PJ_LOG(5,(sub->obj_name, "%s %s timer",
Expand All @@ -509,7 +509,8 @@ static void set_timer( pjsip_evsub *sub, int timer_id,
sub->timer.id = TIMER_TYPE_NONE;
}

if (timer_id != TIMER_TYPE_NONE && seconds > 0) {
if (timer_id != TIMER_TYPE_NONE && seconds != PJSIP_EXPIRES_NOT_SPECIFIED)
{
pj_time_val timeout;

PJ_ASSERT_ON_FAIL(timer_id>TIMER_TYPE_NONE && timer_id<TIMER_TYPE_MAX,
Expand Down Expand Up @@ -1068,7 +1069,7 @@ PJ_DEF(const pj_str_t*) pjsip_evsub_get_termination_reason(pjsip_evsub *sub)
*/
PJ_DEF(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub,
const pjsip_method *method,
pj_int32_t expires,
pj_uint32_t expires,
pjsip_tx_data **p_tdata)
{
pjsip_tx_data *tdata;
Expand Down Expand Up @@ -1096,7 +1097,7 @@ PJ_DEF(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub,
pjsip_hdr_shallow_clone(tdata->pool, sub->event));

/* Update and add expires header: */
if (expires >= 0)
if (expires != PJSIP_EXPIRES_NOT_SPECIFIED)
sub->expires->ivalue = expires;
pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*)
pjsip_hdr_shallow_clone(tdata->pool, sub->expires));
Expand Down Expand Up @@ -1996,11 +1997,11 @@ static void on_tsx_state_uac( pjsip_evsub *sub, pjsip_transaction *tsx,
* is "active" or "pending", AND the header contains expires param.
*/
if (sub->expires->ivalue != 0 &&
sub_state->expires_param >= 0 &&
sub_state->expires_param != PJSIP_EXPIRES_NOT_SPECIFIED &&
(pj_stricmp(&sub_state->sub_state, &STR_ACTIVE)==0 ||
pj_stricmp(&sub_state->sub_state, &STR_PENDING)==0))
{
int next_refresh = sub_state->expires_param;
unsigned next_refresh = sub_state->expires_param;
unsigned timeout;

update_expires(sub, next_refresh);
Expand Down Expand Up @@ -2099,7 +2100,7 @@ static void on_tsx_state_uas( pjsip_evsub *sub, pjsip_transaction *tsx,

evpkg = find_pkg(&event_hdr->event_type);
if (evpkg) {
if (expires->ivalue < (pj_int32_t)evpkg->pkg_expires)
if (expires->ivalue < evpkg->pkg_expires)
sub->expires->ivalue = expires->ivalue;
else
sub->expires->ivalue = evpkg->pkg_expires;
Expand Down

0 comments on commit 3f58d4d

Please sign in to comment.