http: fix processing server http data separated by \n instead of \r\n
authorFelix Fietkau <nbd@openwrt.org>
Sat, 23 Jan 2016 18:49:55 +0000 (19:49 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 23 Jan 2016 18:49:55 +0000 (19:49 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-http.c

index 6fc30da1ea28b153bb8231ba518bde473b038992..e58cf274b3a6cef5b06929462c7638f3d648afa1 100644 (file)
@@ -663,28 +663,33 @@ static void __uclient_notify_read(struct uclient_http *uh)
                return;
 
        if (uh->state < HTTP_STATE_RECV_DATA) {
-               char *sep;
+               char *sep, *next;
                int cur_len;
 
                do {
-                       sep = strstr(data, "\r\n");
+                       sep = strchr(data, '\n');
                        if (!sep)
                                break;
 
+                       next = sep + 1;
+                       if (sep > data && sep[-1] == '\r')
+                               sep--;
+
                        /* Check for multi-line HTTP headers */
                        if (sep > data) {
-                               if (!sep[2])
+                               if (!*next)
                                        return;
 
-                               if (isspace(sep[2]) && sep[2] != '\r') {
+                               if (isspace(*next) && *next != '\r' && *next != '\n') {
                                        sep[0] = ' ';
-                                       sep[1] = ' ';
+                                       if (sep + 1 < next)
+                                               sep[1] = ' ';
                                        continue;
                                }
                        }
 
                        *sep = 0;
-                       cur_len = sep + 2 - data;
+                       cur_len = next - data;
                        uclient_parse_http_line(uh, data);
                        if (seq != uh->seq)
                                return;