Avoid ambiguous change of SsdpEvent in unique_service_name.

Handle overflow before changing SsdpEvent.
Because the behavior of "snprintf" is platform dependent in such case.
This commit is contained in:
Yoichi NAKAYAMA 2012-03-14 22:55:13 +09:00
parent 35819a7a44
commit f299d6597a
2 changed files with 13 additions and 7 deletions

View File

@ -2,6 +2,13 @@
Version 1.6.16
*******************************************************************************
2012-03-14 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
Avoid ambiguous change of SsdpEvent in unique_service_name.
Handle overflow before changing SsdpEvent.
Because the behavior of "snprintf" is platform dependent in such case.
2012-03-14 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
SF Bug Tracker id 3502958 - The commit 5944960e prevents a pupnp client (amule) from receiving replies from an IGD device.

View File

@ -458,7 +458,6 @@ int unique_service_name(char *cmd, SsdpEvent *Evt)
char *ptr3 = NULL;
int CommandFound = 0;
size_t n = (size_t)0;
int rc = 0;
if (strstr(cmd, "uuid:schemas") != NULL) {
ptr1 = strstr(cmd, ":device");
@ -471,10 +470,10 @@ int unique_service_name(char *cmd, SsdpEvent *Evt)
else
return -1;
if (ptr3 != NULL) {
rc = snprintf(Evt->UDN, sizeof(Evt->UDN), "uuid:%s",
ptr3 + 1);
if (rc < 0 || (unsigned int) rc >= sizeof(Evt->UDN))
if (strlen("uuid:") + strlen(ptr3 + 1) >= sizeof(Evt->UDN))
return -1;
snprintf(Evt->UDN, sizeof(Evt->UDN), "uuid:%s",
ptr3 + 1);
}
else
return -1;
@ -483,10 +482,10 @@ int unique_service_name(char *cmd, SsdpEvent *Evt)
n = (size_t)ptr3 - (size_t)ptr1;
strncpy(TempBuf, ptr1, n);
TempBuf[n] = '\0';
rc = snprintf(Evt->DeviceType, sizeof(Evt->DeviceType),
"urn%s", TempBuf);
if (rc < 0 || (unsigned int) rc >= sizeof(Evt->DeviceType))
if (strlen("urn") + strlen(TempBuf) >= sizeof(Evt->DeviceType))
return -1;
snprintf(Evt->DeviceType, sizeof(Evt->DeviceType),
"urn%s", TempBuf);
} else
return -1;
return 0;