summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/HTTPStream.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-02-02 13:27:08 -0800
committerAndreas Huber <andih@google.com>2010-02-02 14:43:08 -0800
commit7f8b69feef7bf9395ba4fda0619240f1237552b1 (patch)
tree020f120aae226ec911e0a555050a6ae4a2562582 /media/libstagefright/HTTPStream.cpp
parent7574ca60ce85f816d3d7f6ee7a74285ff6b72a98 (diff)
downloadframeworks_av-7f8b69feef7bf9395ba4fda0619240f1237552b1.zip
frameworks_av-7f8b69feef7bf9395ba4fda0619240f1237552b1.tar.gz
frameworks_av-7f8b69feef7bf9395ba4fda0619240f1237552b1.tar.bz2
Workaround for misbehaving HTTP servers that terminate header lines with a single newline instead of the required CRLF sequence.
related-to-bug: 2414022
Diffstat (limited to 'media/libstagefright/HTTPStream.cpp')
-rw-r--r--media/libstagefright/HTTPStream.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp
index 7293c11..3711aca 100644
--- a/media/libstagefright/HTTPStream.cpp
+++ b/media/libstagefright/HTTPStream.cpp
@@ -52,7 +52,7 @@ status_t HTTPStream::connect(const char *server, int port) {
CHECK_EQ(mSocket, -1);
mSocket = socket(AF_INET, SOCK_STREAM, 0);
-
+
if (mSocket < 0) {
return UNKNOWN_ERROR;
}
@@ -132,6 +132,14 @@ status_t HTTPStream::send(const char *data) {
return send(data, strlen(data));
}
+// A certain application spawns a local webserver that sends invalid responses,
+// specifically it terminates header line with only a newline instead of the
+// CRLF (carriage-return followed by newline) required by the HTTP specs.
+// The workaround accepts both behaviours but could potentially break
+// legitimate responses that use a single newline to "fold" headers, which is
+// why it's not yet on by default.
+#define WORKAROUND_FOR_MISSING_CR 0
+
status_t HTTPStream::receive_line(char *line, size_t size) {
if (mState != CONNECTED) {
return ERROR_NOT_CONNECTED;
@@ -157,16 +165,27 @@ status_t HTTPStream::receive_line(char *line, size_t size) {
return ERROR_CONNECTION_LOST;
}
- if (saw_CR && c == '\n') {
+#if WORKAROUND_FOR_MISSING_CR
+ if (c == '\n') {
+ // We have a complete line.
+
+ line[saw_CR ? length - 1 : length] = '\0';
+ return OK;
+ }
+#else
+ if (saw_CR && c == '\n') {
// We have a complete line.
line[length - 1] = '\0';
return OK;
}
+#endif
saw_CR = (c == '\r');
- CHECK(length + 1 < size);
+ if (length + 1 >= size) {
+ return ERROR_MALFORMED;
+ }
line[length++] = c;
}
}
@@ -175,7 +194,7 @@ status_t HTTPStream::receive_header(int *http_status) {
*http_status = -1;
mHeaders.clear();
- char line[1024];
+ char line[2048];
status_t err = receive_line(line, sizeof(line));
if (err != OK) {
return err;