-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: maxfwd module incorrectly decrements header twice if the max-forwards… #3511
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,63 +38,68 @@ | |
#define MF_HDR "Max-Forwards: " | ||
#define MF_HDR_LEN (sizeof(MF_HDR) - 1) | ||
|
||
/* do a tricky thing and keep the parsed value of MAXFWD hdr incremented | ||
* by one in order to make difference between 0 (not set) | ||
* and 0 (zero value) - bogdan */ | ||
#define IS_MAXWD_STORED(_msg_) \ | ||
#define IS_MAXFWD_STORED(_msg_) \ | ||
((_msg_)->maxforwards->parsed) | ||
#define STORE_MAXWD_VAL(_msg_,_val_) \ | ||
(_msg_)->maxforwards->parsed = ((void*)(long)((_val_)+1)) | ||
#define FETCH_MAXWD_VAL(_msg_) \ | ||
(((int)(long)(_msg_)->maxforwards->parsed)-1) | ||
#define STORE_MAXFWD_VAL(_msg_,_val_) \ | ||
(_msg_)->maxforwards->parsed = ((void*)(long)((_val_))) | ||
#define FETCH_MAXFWD_VAL(_msg_) \ | ||
(((int)(long)(_msg_)->maxforwards->parsed)) | ||
|
||
/* looks for the MAX FORWARDS header | ||
returns the its value, -1 if is not present or -2 for error */ | ||
int is_maxfwd_present( struct sip_msg* msg , str *foo) | ||
returns the its value, -1 if is not present or -2 for error or 0 for present */ | ||
int is_maxfwd_present(struct sip_msg* msg, str *mf_value) | ||
{ | ||
int x, err; | ||
int parsed_val, err; | ||
|
||
/* lookup into the message for MAX FORWARDS header*/ | ||
if ( !msg->maxforwards ) { | ||
if ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){ | ||
LM_ERR("parsing MAX_FORWARD header failed!\n"); | ||
if (!msg->maxforwards) { | ||
if (parse_headers(msg , HDR_MAXFORWARDS_F, 0) == -1){ | ||
LM_ERR("parsing Max-Forwards header failed!\n"); | ||
return -2; | ||
} | ||
|
||
if (!msg->maxforwards) { | ||
LM_DBG("max_forwards header not found!\n"); | ||
LM_DBG("Max-Forwards header not found!\n"); | ||
return -1; | ||
} | ||
} else if (IS_MAXWD_STORED(msg)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else/if is removed here in favour of an if after this is so that we can do the |
||
trim_len( foo->len , foo->s , msg->maxforwards->body ); | ||
return FETCH_MAXWD_VAL(msg); | ||
} | ||
|
||
/* if header is present, trim to get only the string containing numbers */ | ||
trim_len( foo->len , foo->s , msg->maxforwards->body ); | ||
trim_len(mf_value->len , mf_value->s, msg->maxforwards->body); | ||
|
||
/* even if the parsed is 0 because it's a null pointer or a zero value | ||
* it doesn't matter and we can assume it's not stored and just parse the body | ||
*/ | ||
if (IS_MAXFWD_STORED(msg)) { | ||
return FETCH_MAXFWD_VAL(msg); | ||
} | ||
|
||
/* convert from string to number */ | ||
x = str2s( foo->s,foo->len,&err); | ||
if (err){ | ||
LM_ERR("unable to parse the max forwards number\n"); | ||
parsed_val = str2s(mf_value->s, mf_value->len, &err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assume in this scenario that |
||
if (err) { | ||
LM_ERR("unable to parse the Max-Forwards value\n"); | ||
|
||
return -2; | ||
} | ||
|
||
/* store the parsed values */ | ||
STORE_MAXWD_VAL(msg, x); | ||
LM_DBG("value = %d \n",x); | ||
return x; | ||
STORE_MAXFWD_VAL(msg, parsed_val); | ||
LM_DBG("value = %d \n", parsed_val); | ||
|
||
return parsed_val; | ||
} | ||
|
||
|
||
|
||
int decrement_maxfwd( struct sip_msg* msg , int x, str *s) | ||
int decrement_maxfwd( struct sip_msg* msg, int x, str *s) | ||
{ | ||
int i; | ||
|
||
/* decrement the value */ | ||
x--; | ||
|
||
/* update the stored value */ | ||
STORE_MAXWD_VAL(msg, x); | ||
STORE_MAXFWD_VAL(msg, x); | ||
|
||
/* rewriting the max-fwd value in the message (buf and orig) */ | ||
for(i = s->len - 1; i >= 0; i--) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the macros from
MAXWD
toMAXFWD
also some of the changes here are whitespace changes to be consistent