- September 1, 2008
- 21,577
- 8,224
- Home Country
- New Zealand
I concur - the UPnP thing has nothing to do with firewalls.
The message comes from here:
https://github.com/MediaPortal/Medi...tructure/Utils/HTTP/SimpleHTTPMessage.cs#L148
Basically MP2 expects the message format to be one or more headers of the format:
[<whitespace]<header name>[<whitespace]:[<whitespace]<header value>[<whitespace]\r\n
The final header line should be followed by an additional \r\n, and then comes the body.
The way I read the code, the most likely way this message could be generated is if the stack receives a message with a whitespace header line or without a body.
Hopefully the first case is obvious. It shouldn't happen... but such is life when programmers are lazy!
In the second case it would be enough for the message to have no body and end with \r\n followed by optional whitespace.
In both cases it is a completely harmless situation apart from the annoying log entries.
I'd propose to solve this by:
...or...
...or...
Basically the goal is to not log unless a non-whitespace line does not contain a colon ).
I note that the line "string header = Encoding.UTF8.GetString(data, 0, numHeaderBytes - 4);" is actually a little dangerous. Consider what happens:
Second case will lead to loss or modification of header data. Not good.
mm
The message comes from here:
https://github.com/MediaPortal/Medi...tructure/Utils/HTTP/SimpleHTTPMessage.cs#L148
Basically MP2 expects the message format to be one or more headers of the format:
[<whitespace]<header name>[<whitespace]:[<whitespace]<header value>[<whitespace]\r\n
The final header line should be followed by an additional \r\n, and then comes the body.
The way I read the code, the most likely way this message could be generated is if the stack receives a message with a whitespace header line or without a body.
Hopefully the first case is obvious. It shouldn't happen... but such is life when programmers are lazy!
In the second case it would be enough for the message to have no body and end with \r\n followed by optional whitespace.
In both cases it is a completely harmless situation apart from the annoying log entries.
I'd propose to solve this by:
Code:
int index = line.IndexOf(':');
if (index == -1)
if (string.IsNullOrEmpty(line))
continue;
throw new InvalidDataException("Invalid HTTP header line '{0}'", line);
...or...
Code:
string header = Encoding.UTF8.GetString(data, 0, numHeaderBytes).Trim();
string[] lines = header.Split(new string[] {"\r\n"}, StringSplitOptions.None);
...or...
Code:
string header = Encoding.UTF8.GetString(data, 0, numHeaderBytes);
string[] lines = header.Split(new string[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
Basically the goal is to not log unless a non-whitespace line does not contain a colon ).
I note that the line "string header = Encoding.UTF8.GetString(data, 0, numHeaderBytes - 4);" is actually a little dangerous. Consider what happens:
- In the unlikely case that the message length is less than 4 bytes.
- The top while loop is escaped due to running out of bytes.
Second case will lead to loss or modification of header data. Not good.
mm