ssdp: Fix UDP sendto bug
The size of the client address may be modified by recfrom. So, the last parameter of sendto should be the modified size.
This commit is contained in:
parent
ca08f4540f
commit
914ac12302
11
minissdp.c
11
minissdp.c
@ -217,7 +217,7 @@ _usleep(long usecs)
|
||||
* to a SSDP "M-SEARCH" */
|
||||
static void
|
||||
SendSSDPResponse(int s, struct sockaddr_in sockname, int st_no,
|
||||
const char *host, unsigned short port)
|
||||
const char *host, unsigned short port, socklen_t len_r)
|
||||
{
|
||||
int l, n;
|
||||
char buf[512];
|
||||
@ -255,7 +255,7 @@ SendSSDPResponse(int s, struct sockaddr_in sockname, int st_no,
|
||||
inet_ntoa(sockname.sin_addr), ntohs(sockname.sin_port),
|
||||
known_service_types[st_no]);
|
||||
n = sendto(s, buf, l, 0,
|
||||
(struct sockaddr *)&sockname, sizeof(struct sockaddr_in) );
|
||||
(struct sockaddr *)&sockname, len_r);
|
||||
if (n < 0)
|
||||
DPRINTF(E_ERROR, L_SSDP, "sendto(udp): %s\n", strerror(errno));
|
||||
}
|
||||
@ -489,6 +489,7 @@ ProcessSSDPRequest(int s, unsigned short port)
|
||||
int i;
|
||||
char *st = NULL, *mx = NULL, *man = NULL, *mx_end = NULL;
|
||||
int man_len = 0;
|
||||
socklen_t len_r = sizeof(struct sockaddr_in);
|
||||
#ifdef __linux__
|
||||
char cmbuf[CMSG_SPACE(sizeof(struct in_pktinfo))];
|
||||
struct iovec iovec = {
|
||||
@ -506,10 +507,10 @@ ProcessSSDPRequest(int s, unsigned short port)
|
||||
|
||||
n = recvmsg(s, &mh, 0);
|
||||
#else
|
||||
socklen_t len_r = sizeof(struct sockaddr_in);
|
||||
|
||||
n = recvfrom(s, bufr, sizeof(bufr)-1, 0,
|
||||
(struct sockaddr *)&sendername, &len_r);
|
||||
len_r = MIN(len_r, sizeof(struct sockaddr_in));
|
||||
#endif
|
||||
if (n < 0)
|
||||
{
|
||||
@ -723,7 +724,7 @@ ProcessSSDPRequest(int s, unsigned short port)
|
||||
}
|
||||
_usleep(random()>>20);
|
||||
SendSSDPResponse(s, sendername, i,
|
||||
host, port);
|
||||
host, port, len_r);
|
||||
return;
|
||||
}
|
||||
/* Responds to request with ST: ssdp:all */
|
||||
@ -734,7 +735,7 @@ ProcessSSDPRequest(int s, unsigned short port)
|
||||
{
|
||||
l = strlen(known_service_types[i]);
|
||||
SendSSDPResponse(s, sendername, i,
|
||||
host, port);
|
||||
host, port, len_r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user