mirror of
https://github.com/nmap/nmap.git
synced 2025-12-24 08:29:04 +00:00
Actually pass the bigger buffer size when padding with nulls.
This commit is contained in:
@@ -285,22 +285,25 @@ int block_socket(int sd) {
|
||||
only). Pass NULL or an empty string to remove device binding. */
|
||||
int socket_bindtodevice(int sd, const char *device) {
|
||||
char padded[sizeof(int)];
|
||||
size_t len;
|
||||
|
||||
len = strlen(device) + 1;
|
||||
/* In Linux 2.6.20 and earlier, there is a bug in SO_BINDTODEVICE that causes
|
||||
EINVAL to be returned if the optlen < sizeof(int); this happens for example
|
||||
with the interface names "" and "lo". Pad the string with null characters
|
||||
so it is above this limit if necessary.
|
||||
http://article.gmane.org/gmane.linux.network/71887
|
||||
http://article.gmane.org/gmane.linux.network/72216 */
|
||||
if (strlen(device) + 1 < sizeof(padded)) {
|
||||
if (len < sizeof(padded)) {
|
||||
/* We rely on strncpy padding with nulls here. */
|
||||
strncpy(padded, device, sizeof(padded));
|
||||
device = padded;
|
||||
len = sizeof(padded);
|
||||
}
|
||||
|
||||
#ifdef SO_BINDTODEVICE
|
||||
/* Linux-specific sockopt asking to use a specific interface. See socket(7). */
|
||||
if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) < 0)
|
||||
if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, device, len) < 0)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user