mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Fix crash in socket_bindtodevice: NULL device is permissible
This commit is contained in:
@@ -1120,7 +1120,9 @@ int netutil_raw_socket(const char *device) {
|
|||||||
netutil_perror("setsockopt(SO_BROADCAST) failed");
|
netutil_perror("setsockopt(SO_BROADCAST) failed");
|
||||||
}
|
}
|
||||||
sethdrinclude(rawsd);
|
sethdrinclude(rawsd);
|
||||||
|
if (device) {
|
||||||
socket_bindtodevice(rawsd, device);
|
socket_bindtodevice(rawsd, device);
|
||||||
|
}
|
||||||
|
|
||||||
return rawsd;
|
return rawsd;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -266,8 +266,9 @@ int block_socket(int sd) {
|
|||||||
int socket_bindtodevice(int sd, const char *device) {
|
int socket_bindtodevice(int sd, const char *device) {
|
||||||
#ifdef SO_BINDTODEVICE
|
#ifdef SO_BINDTODEVICE
|
||||||
char padded[sizeof(int)];
|
char padded[sizeof(int)];
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
|
|
||||||
|
if (device) {
|
||||||
len = strlen(device) + 1;
|
len = strlen(device) + 1;
|
||||||
/* In Linux 2.6.20 and earlier, there is a bug in SO_BINDTODEVICE that causes
|
/* 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
|
EINVAL to be returned if the optlen < sizeof(int); this happens for example
|
||||||
@@ -281,6 +282,7 @@ int socket_bindtodevice(int sd, const char *device) {
|
|||||||
device = padded;
|
device = padded;
|
||||||
len = sizeof(padded);
|
len = sizeof(padded);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Linux-specific sockopt asking to use a specific interface. See socket(7). */
|
/* Linux-specific sockopt asking to use a specific interface. See socket(7). */
|
||||||
if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, device, len) < 0)
|
if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, device, len) < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user