File: handle-missing-content-length.patch

package info (click to toggle)
libest 3.2.0%2Bds-1.1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 11,792 kB
  • sloc: ansic: 60,980; java: 12,082; sh: 4,956; python: 4,474; xml: 385; makefile: 290
file content (50 lines) | stat: -rw-r--r-- 1,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Subject: Handle missing Content-Length in server replies
Author: Andreas Schärtl <andreas@schaertl.me>
Forwarded: https://github.com/cisco/libest/pull/125
Last-Update: 2023-12-21

--- a/src/est/est_client_http.c
+++ b/src/est/est_client_http.c
@@ -1457,8 +1457,7 @@
         return EST_ERR_HTTP_UNSUPPORTED;
     }
     if (content_length_present == 0) {
-        EST_LOG_ERR("Missing HTTP content length header");
-        return EST_ERR_HTTP_UNSUPPORTED;
+        EST_LOG_INFO("Missing HTTP content length header");
     }
 
     return EST_ERR_NONE;
@@ -1557,6 +1556,7 @@
     unsigned char *raw_buf = NULL, *payload_skip_extra = NULL;
     unsigned char *payload, *payload_buf;
     int raw_len = 0;
+    int body_len;
     errno_t safec_rc;
 
 
@@ -1763,6 +1763,15 @@
              */
             rv = est_io_check_http_hdrs(hdrs, hdr_cnt, op, cert_buf_len);
             if (rv == EST_ERR_NONE) {
+                body_len = (raw_len + raw_buf) - payload;
+
+                if (*cert_buf_len == -1) {
+                    /*
+                     * Connection is being closed. Allocate just enough
+                     * for the body we have received.
+                     */
+                    *cert_buf_len = body_len;
+                }
 
                 EST_LOG_INFO("HTTP Content len=%d", *cert_buf_len);
 
@@ -1778,7 +1787,7 @@
                     rv = EST_ERR_HTTP_UNSUPPORTED;
                     *cert_buf_len = 0;
                     *cert_buf = NULL;
-                } else if (*cert_buf_len != (raw_len + raw_buf) - payload) {
+                } else if (*cert_buf_len != body_len) {
                     EST_LOG_ERR(
                         "Content Length (%d) and body length (%d) mismatch.",
                         *cert_buf_len, (raw_len + raw_buf) - payload);