mirror of
https://github.com/moonlight-stream/Internet-Hosting-Tool.git
synced 2026-06-18 14:41:04 +00:00
Fix handling of malformed SSDP responses
This commit is contained in:
+17
-2
@@ -94,11 +94,22 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
|
|||||||
char* protocol = strtok(responseBuffer, " ");
|
char* protocol = strtok(responseBuffer, " ");
|
||||||
char* statusCodeStr = strtok(nullptr, " ");
|
char* statusCodeStr = strtok(nullptr, " ");
|
||||||
char* statusMessage = strtok(nullptr, "\r");
|
char* statusMessage = strtok(nullptr, "\r");
|
||||||
if (_stricmp(protocol, "HTTP/1.0") && _stricmp(protocol, "HTTP/1.1")) {
|
|
||||||
|
// Check for a valid response header
|
||||||
|
if (protocol == nullptr) {
|
||||||
|
printf("Missing protocol in SSDP header\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (statusCodeStr == nullptr) {
|
||||||
|
printf("Missing status code in SSDP header\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// FIXME: Should we require statusMessage too?
|
||||||
|
else if (_stricmp(protocol, "HTTP/1.0") && _stricmp(protocol, "HTTP/1.1")) {
|
||||||
printf("Unexpected protocol: %s\n", protocol);
|
printf("Unexpected protocol: %s\n", protocol);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (atoi(statusCodeStr) != 200) {
|
else if (atoi(statusCodeStr) != 200) {
|
||||||
printf("Unexpected status: %s %s\n", statusCodeStr, statusMessage);
|
printf("Unexpected status: %s %s\n", statusCodeStr, statusMessage);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -109,6 +120,10 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
|
|||||||
char* st = nullptr;
|
char* st = nullptr;
|
||||||
while (char* headerName = strtok(nullptr, "\r\n:")) {
|
while (char* headerName = strtok(nullptr, "\r\n:")) {
|
||||||
char* headerValue = strtok(nullptr, "\r");
|
char* headerValue = strtok(nullptr, "\r");
|
||||||
|
if (headerValue == nullptr) {
|
||||||
|
printf("Unexpected end of SSDP header\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip leading spaces
|
// Skip leading spaces
|
||||||
while (*headerValue == ' ') headerValue++;
|
while (*headerValue == ' ') headerValue++;
|
||||||
|
|||||||
Reference in New Issue
Block a user