Skip to content

Commit

Permalink
Fix ubsan complaint about incorrect left-shift in generate_local_port()
Browse files Browse the repository at this point in the history
The value of "n" used to calculate get the unique port within application
is 10 bit.
This change applies corresponding mask to n, prior to left-shifting it.
  • Loading branch information
ievenbach committed Apr 24, 2024
1 parent 96ddcd9 commit 4186c1d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static uint32_t generate_local_port(void)
nl_write_unlock(&port_map_lock);

/* ensure we don't return zero. */
pid = pid + (n << 22);
pid = pid + ((n&0x3ff) << 22);
return pid ? pid : 1024;
}
}
Expand Down

0 comments on commit 4186c1d

Please sign in to comment.