mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 06:40:48 +00:00
Clarify HopByHop padding code, addressing LGTM.com finding
This commit is contained in:
parent
95d98fe6ae
commit
8bb25f535c
1 changed files with 9 additions and 9 deletions
|
|
@ -369,21 +369,21 @@ int HopByHopHeader::addOption(u8 type, u8 len, const u8 *data){
|
|||
* this method adds the necessary padding (either PadN or Pad1 options)*/
|
||||
int HopByHopHeader::addPadding(){
|
||||
u8 zeroes[8]={0,0,0,0,0,0,0,0};
|
||||
int required_octets=8-(this->length%8);
|
||||
// required_octets in range [0,7]
|
||||
int required_octets=(8 - (this->length % 8)) % 8;
|
||||
|
||||
/* Make sure we have enough space for the padding. */
|
||||
if ( (this->length+required_octets) > HOPBYHOP_MAX_HEADER_LEN )
|
||||
return OP_FAILURE;
|
||||
|
||||
/* Insert Pad1 or PadN to fill the necessary octets */
|
||||
if(required_octets>0 && required_octets<8){
|
||||
if(required_octets==1){
|
||||
curr_option[0]=EXTOPT_PAD1;
|
||||
curr_option++;
|
||||
this->length++;
|
||||
}else{
|
||||
this->addOption(EXTOPT_PADN, required_octets-2, zeroes );
|
||||
}
|
||||
if (required_octets == 1) {
|
||||
curr_option[0]=EXTOPT_PAD1;
|
||||
curr_option++;
|
||||
this->length++;
|
||||
}
|
||||
else if (required_octets > 0) {
|
||||
this->addOption(EXTOPT_PADN, required_octets-2, zeroes );
|
||||
}
|
||||
assert(this->length%8==0);
|
||||
this->h.len=(this->length/8)-1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue