| 1 |
|
| /* Private receive checks for facts libnghttp2 discards in RFC 9218 mode. |
| 2 |
|
| * libnghttp2 still owns frame decoding, HPACK, flow control and active streams. |
| 3 |
|
| * Only frame envelopes and small PRIORITY/WINDOW_UPDATE fields are inspected. |
| 4 |
|
| */ |
| 5 |
|
| #define UB_H2_HISTORY_LIMIT 1024 |
| 6 |
|
| #define UB_H2_CLOSED 1 |
| 7 |
|
| #define UB_H2_LOCAL_RESET 2 |
| 8 |
|
| #define UB_H2_SKIPPED 3 |
| 9 |
|
| |
| 10 |
|
| typedef struct { |
| 11 |
|
| int32_t first; |
| 12 |
|
| int32_t last; |
| 13 |
|
| unsigned char kind; |
| 14 |
|
| } ub_h2_history; |
| 15 |
|
| |
| 16 |
|
| typedef struct { |
| 17 |
|
| ub_h2_history *history; |
| 18 |
|
| size_t count; |
| 19 |
|
| size_t capacity; |
| 20 |
|
| int32_t last_peer_id; |
| 21 |
|
| int32_t current_rst; |
| 22 |
|
| int32_t continuation; |
| 23 |
|
| size_t payload_left; |
| 24 |
|
| size_t prefix_used; |
| 25 |
|
| size_t preface_left; |
| 26 |
|
| unsigned char prefix[14]; |
| 27 |
|
| int ready; |
| 28 |
|
| int failed; |
| 29 |
|
| } ub_h2_guard; |
| 30 |
|
| |
| 31 |
|
| static int |
| 32 |
83 |
| ub_h2_reject(ub_h2_guard *g, nghttp2_session *session, |
| 33 |
|
| uint32_t code, const char *reason) |
| 34 |
|
| { |
| 35 |
|
| int rv; |
| 36 |
83 |
▶ | if (g->failed) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->failed) return 0; |
0 |
83 |
83 |
|
| 37 |
|
| (void)reason; /* Diagnostic label at the call site; public nghttp2 API. */ |
| 38 |
83 |
| rv = nghttp2_session_terminate_session(session, code); |
| 39 |
83 |
▶ | if (rv == 0) g->failed = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv == 0) g->failed = 1; |
83 |
0 |
83 |
|
| 40 |
83 |
| return rv; |
| 41 |
|
| } |
| 42 |
|
| |
| 43 |
|
| /* Sorted, coalesced ranges of odd request stream IDs. Normal sequential |
| 44 |
|
| * traffic uses one range, regardless of the number of completed requests. |
| 45 |
|
| * Bound pathological fragmentation instead of forgetting reset-race facts. |
| 46 |
|
| */ |
| 47 |
|
| static int |
| 48 |
14675 |
| ub_h2_remember(ub_h2_guard *g, nghttp2_session *session, |
| 49 |
|
| int32_t first, int32_t last, unsigned char kind) |
| 50 |
|
| { |
| 51 |
14675 |
| size_t lo = 0, hi = g->count, i; |
| 52 |
|
| ub_h2_history *h; |
| 53 |
14675 |
▶ | if (g->failed || first > last || !(first & 1)) return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| if (g->failed || first > last || !(first & 1)) return 0; |
14675 |
0 |
14675 |
| if (g->failed || first > last || !(first & 1)) return 0; |
7885 |
6790 |
14675 |
| if (g->failed || first > last || !(first & 1)) return 0; |
0 |
7885 |
7885 |
|
| 54 |
26785 |
▶ | while (lo < hi) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (lo < hi) { |
18900 |
7885 |
26785 |
|
| 55 |
18900 |
| size_t mid = lo + (hi - lo) / 2; |
| 56 |
18900 |
▶ | if (g->history[mid].last < first) lo = mid + 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->history[mid].last < first) lo = mid + 1; |
16066 |
2834 |
18900 |
|
| 57 |
2834 |
| else hi = mid; |
| 58 |
|
| } |
| 59 |
7885 |
| i = lo; |
| 60 |
|
| /* Stream-close notifications are unique. Keep existing facts if a |
| 61 |
|
| * duplicate notification nevertheless arrives during teardown. */ |
| 62 |
7885 |
▶ | if (i < g->count && g->history[i].first <= last) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (i < g->count && g->history[i].first <= last) return 0; |
1470 |
6415 |
7885 |
| if (i < g->count && g->history[i].first <= last) return 0; |
0 |
1470 |
1470 |
|
| 63 |
7885 |
▶ | if (i && g->history[i - 1].kind == kind |
Branch: 2 branches
| Branch | True | False | Total |
| if (i && g->history[i - 1].kind == kind |
7696 |
189 |
7885 |
| if (i && g->history[i - 1].kind == kind |
6637 |
1059 |
7696 |
|
| 64 |
6637 |
▶ | && (int64_t)g->history[i - 1].last + 2 == first) { |
Branch: 1 branch
| Branch | True | False | Total |
| && (int64_t)g->history[i - 1].last + 2 == first) { |
6397 |
240 |
6637 |
|
| 65 |
6397 |
| h = &g->history[--i]; |
| 66 |
6397 |
| h->last = last; |
| 67 |
1488 |
▶ | } else if (i < g->count && g->history[i].kind == kind |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (i < g->count && g->history[i].kind == kind |
224 |
1264 |
1488 |
| } else if (i < g->count && g->history[i].kind == kind |
212 |
12 |
224 |
|
| 68 |
212 |
▶ | && (int64_t)last + 2 == g->history[i].first) { |
Branch: 1 branch
| Branch | True | False | Total |
| && (int64_t)last + 2 == g->history[i].first) { |
6 |
206 |
212 |
|
| 69 |
6 |
| g->history[i].first = first; |
| 70 |
6 |
| return 0; |
| 71 |
|
| } else { |
| 72 |
1482 |
▶ | if (g->count == UB_H2_HISTORY_LIMIT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->count == UB_H2_HISTORY_LIMIT) { |
1 |
1481 |
1482 |
|
| 73 |
1 |
| return ub_h2_reject(g, session, NGHTTP2_ENHANCE_YOUR_CALM, |
| 74 |
|
| "stream history fragmentation limit"); |
| 75 |
|
| } |
| 76 |
1481 |
▶ | if (g->count == g->capacity) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->count == g->capacity) { |
167 |
1314 |
1481 |
|
| 77 |
|
| dTHX; /* Windows Perl can route realloc through its interpreter. */ |
| 78 |
167 |
▶ | size_t capacity = g->capacity ? g->capacity * 2 : 8; |
Branch: 1 branch
| Branch | True | False | Total |
| size_t capacity = g->capacity ? g->capacity * 2 : 8; |
8 |
159 |
167 |
|
| 79 |
167 |
| h = (ub_h2_history *)realloc(g->history, capacity * sizeof(*h)); |
| 80 |
167 |
▶ | if (!h) return NGHTTP2_ERR_NOMEM; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) return NGHTTP2_ERR_NOMEM; |
0 |
167 |
167 |
|
| 81 |
167 |
| g->history = h; |
| 82 |
167 |
| g->capacity = capacity; |
| 83 |
|
| } |
| 84 |
1481 |
| memmove(g->history + i + 1, g->history + i, |
| 85 |
1481 |
| (g->count - i) * sizeof(*g->history)); |
| 86 |
1481 |
| ++g->count; |
| 87 |
1481 |
| h = &g->history[i]; |
| 88 |
1481 |
| h->first = first; |
| 89 |
1481 |
| h->last = last; |
| 90 |
1481 |
| h->kind = kind; |
| 91 |
|
| } |
| 92 |
7878 |
▶ | if (i + 1 < g->count && g->history[i + 1].kind == kind |
Branch: 2 branches
| Branch | True | False | Total |
| if (i + 1 < g->count && g->history[i + 1].kind == kind |
1464 |
6414 |
7878 |
| if (i + 1 < g->count && g->history[i + 1].kind == kind |
1450 |
14 |
1464 |
|
| 93 |
1450 |
▶ | && (int64_t)h->last + 2 == g->history[i + 1].first) { |
Branch: 1 branch
| Branch | True | False | Total |
| && (int64_t)h->last + 2 == g->history[i + 1].first) { |
244 |
1206 |
1450 |
|
| 94 |
244 |
| h->last = g->history[i + 1].last; |
| 95 |
244 |
| --g->count; |
| 96 |
244 |
| memmove(g->history + i + 1, g->history + i + 2, |
| 97 |
244 |
| (g->count - i - 1) * sizeof(*g->history)); |
| 98 |
|
| } |
| 99 |
7878 |
| return 0; |
| 100 |
|
| } |
| 101 |
|
| |
| 102 |
|
| static unsigned char |
| 103 |
7594 |
| ub_h2_history_kind(const ub_h2_guard *g, int32_t id) |
| 104 |
|
| { |
| 105 |
7594 |
| size_t lo = 0, hi = g->count; |
| 106 |
7594 |
▶ | if (!(id & 1)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(id & 1)) return 0; |
0 |
7594 |
7594 |
|
| 107 |
18316 |
▶ | while (lo < hi) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (lo < hi) { |
10828 |
7488 |
18316 |
|
| 108 |
10828 |
| size_t mid = lo + (hi - lo) / 2; |
| 109 |
10828 |
| const ub_h2_history *h = &g->history[mid]; |
| 110 |
10828 |
▶ | if (id < h->first) hi = mid; |
Branch: 1 branch
| Branch | True | False | Total |
| if (id < h->first) hi = mid; |
42 |
10786 |
10828 |
|
| 111 |
10786 |
▶ | else if (id > h->last) lo = mid + 1; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (id > h->last) lo = mid + 1; |
10680 |
106 |
10786 |
|
| 112 |
106 |
| else return h->kind; |
| 113 |
|
| } |
| 114 |
7488 |
| return 0; |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
|
| static uint32_t |
| 118 |
8222 |
| ub_h2_u31(const uint8_t *p) |
| 119 |
|
| { |
| 120 |
8222 |
| return ((uint32_t)(p[0] & 0x7f) << 24) |
| 121 |
8222 |
| | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3]; |
| 122 |
|
| } |
| 123 |
|
| |
| 124 |
|
| /* A peer RST_STREAM can arrive after our own reset was serialized. It ends |
| 125 |
|
| * the in-flight-frame exception even though nghttp2 has already freed the |
| 126 |
|
| * stream. Split a coalesced local-reset range without losing its neighbors. |
| 127 |
|
| */ |
| 128 |
|
| static int |
| 129 |
33 |
| ub_h2_peer_reset(ub_h2_guard *g, nghttp2_session *session, int32_t id) |
| 130 |
|
| { |
| 131 |
|
| size_t i; |
| 132 |
|
| int rv; |
| 133 |
33 |
▶ | if (!(id & 1) || ub_h2_history_kind(g, id) != UB_H2_LOCAL_RESET) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(id & 1) || ub_h2_history_kind(g, id) != UB_H2_LOCAL_RESET) return 0; |
33 |
0 |
33 |
| if (!(id & 1) || ub_h2_history_kind(g, id) != UB_H2_LOCAL_RESET) return 0; |
25 |
8 |
33 |
|
| 134 |
8 |
▶ | for (i = 0; i < g->count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < g->count; ++i) { |
8 |
0 |
8 |
|
| 135 |
8 |
| ub_h2_history old = g->history[i]; |
| 136 |
8 |
▶ | if (id < old.first || id > old.last) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (id < old.first || id > old.last) continue; |
8 |
0 |
8 |
| if (id < old.first || id > old.last) continue; |
0 |
8 |
8 |
|
| 137 |
8 |
| --g->count; |
| 138 |
8 |
| memmove(g->history + i, g->history + i + 1, |
| 139 |
8 |
| (g->count - i) * sizeof(*g->history)); |
| 140 |
8 |
▶ | if (id > old.first) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (id > old.first) { |
8 |
0 |
8 |
|
| 141 |
8 |
| rv = ub_h2_remember(g, session, old.first, id - 2, old.kind); |
| 142 |
16 |
▶ | if (rv != 0) return rv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != 0) return rv; |
0 |
8 |
8 |
|
| 143 |
|
| } |
| 144 |
8 |
| rv = ub_h2_remember(g, session, id, id, UB_H2_CLOSED); |
| 145 |
8 |
▶ | if (rv != 0) return rv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != 0) return rv; |
0 |
8 |
8 |
|
| 146 |
8 |
▶ | if (id < old.last) |
Branch: 1 branch
| Branch | True | False | Total |
| if (id < old.last) |
8 |
0 |
8 |
|
| 147 |
8 |
| return ub_h2_remember(g, session, id + 2, old.last, old.kind); |
| 148 |
0 |
| return 0; |
| 149 |
|
| } |
| 150 |
0 |
| return 0; |
| 151 |
|
| } |
| 152 |
|
| |
| 153 |
|
| /* Both public input paths call this routine. Forward borrowed payload windows |
| 154 |
|
| * directly, stopping at frame boundaries so callbacks update history before |
| 155 |
|
| * the next frame is checked. Buffer at most 14 bytes across fragmented reads. |
| 156 |
|
| */ |
| 157 |
|
| static ssize_t |
| 158 |
55719 |
| ub_h2_receive(ub_h2_guard *g, nghttp2_session *session, |
| 159 |
|
| const uint8_t *data, size_t length) |
| 160 |
|
| { |
| 161 |
55719 |
| size_t offset = 0; |
| 162 |
|
| ssize_t rv; |
| 163 |
111025 |
▶ | while (offset < length) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (offset < length) { |
58879 |
52146 |
111025 |
|
| 164 |
|
| size_t n, frame_length, need; |
| 165 |
|
| const uint8_t *p; |
| 166 |
|
| int buffered; |
| 167 |
|
| uint8_t type, flags; |
| 168 |
|
| int32_t id; |
| 169 |
|
| unsigned char kind; |
| 170 |
|
| int inspect_priority, inspect_window; |
| 171 |
|
| |
| 172 |
58879 |
▶ | if (g->failed || !nghttp2_session_want_read(session)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (g->failed || !nghttp2_session_want_read(session)) |
58631 |
248 |
58879 |
| if (g->failed || !nghttp2_session_want_read(session)) |
0 |
58631 |
58631 |
|
| 173 |
248 |
| return (ssize_t)length; |
| 174 |
|
| |
| 175 |
58631 |
▶ | if (g->preface_left || g->payload_left) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (g->preface_left || g->payload_left) { |
57645 |
986 |
58631 |
| if (g->preface_left || g->payload_left) { |
46268 |
11377 |
57645 |
|
| 176 |
47254 |
▶ | size_t *left = g->preface_left ? &g->preface_left : &g->payload_left; |
Branch: 1 branch
| Branch | True | False | Total |
| size_t *left = g->preface_left ? &g->preface_left : &g->payload_left; |
986 |
46268 |
47254 |
|
| 177 |
47254 |
| n = length - offset; |
| 178 |
47254 |
▶ | if (n > *left) n = *left; |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > *left) n = *left; |
1534 |
45720 |
47254 |
|
| 179 |
47254 |
| rv = nghttp2_session_mem_recv(session, data + offset, n); |
| 180 |
47254 |
▶ | if (rv < 0) return rv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv < 0) return rv; |
1 |
47253 |
47254 |
|
| 181 |
47253 |
▶ | if ((size_t)rv != n) return NGHTTP2_ERR_CALLBACK_FAILURE; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((size_t)rv != n) return NGHTTP2_ERR_CALLBACK_FAILURE; |
0 |
47253 |
47253 |
|
| 182 |
47253 |
| *left -= n; |
| 183 |
47253 |
| offset += n; |
| 184 |
47253 |
| continue; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
11377 |
▶ | buffered = g->prefix_used || length - offset < 9; |
Branch: 2 branches
| Branch | True | False | Total |
| buffered = g->prefix_used || length - offset < 9; |
8135 |
3242 |
11377 |
| buffered = g->prefix_used || length - offset < 9; |
1936 |
6199 |
8135 |
|
| 188 |
11377 |
▶ | if (buffered) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffered) { |
5178 |
6199 |
11377 |
|
| 189 |
5178 |
| n = 9 - (g->prefix_used < 9 ? g->prefix_used : 9); |
| 190 |
5178 |
▶ | if (n > length - offset) n = length - offset; |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > length - offset) n = length - offset; |
3198 |
1980 |
5178 |
|
| 191 |
5178 |
| memcpy(g->prefix + g->prefix_used, data + offset, n); |
| 192 |
5178 |
| g->prefix_used += n; |
| 193 |
5178 |
| offset += n; |
| 194 |
5178 |
▶ | if (g->prefix_used < 9) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->prefix_used < 9) break; |
3198 |
1980 |
5178 |
|
| 195 |
1980 |
| p = g->prefix; |
| 196 |
|
| } else { |
| 197 |
6199 |
| p = data + offset; |
| 198 |
|
| } |
| 199 |
8179 |
| frame_length = ((size_t)p[0] << 16) | ((size_t)p[1] << 8) | p[2]; |
| 200 |
8179 |
| type = p[3]; |
| 201 |
8179 |
| flags = p[4]; |
| 202 |
8179 |
| id = (int32_t)ub_h2_u31(p + 5); |
| 203 |
|
| |
| 204 |
|
| /* Invalid sizes, the initial SETTINGS requirement, and interleaved |
| 205 |
|
| * header blocks are libnghttp2's responsibility and take precedence. */ |
| 206 |
7960 |
▶ | inspect_priority = g->ready && !g->continuation |
Branch: 1 branch
| Branch | True | False | Total |
| inspect_priority = g->ready && !g->continuation |
7952 |
8 |
7960 |
|
| 207 |
7952 |
▶ | && type == NGHTTP2_PRIORITY && frame_length == 5 |
Branch: 2 branches
| Branch | True | False | Total |
| && type == NGHTTP2_PRIORITY && frame_length == 5 |
48 |
7904 |
7952 |
| && type == NGHTTP2_PRIORITY && frame_length == 5 |
48 |
0 |
48 |
|
| 208 |
16139 |
▶ | && nghttp2_session_get_remote_settings( |
Branch: 2 branches
| Branch | True | False | Total |
| && nghttp2_session_get_remote_settings( |
7960 |
219 |
8179 |
| && nghttp2_session_get_remote_settings( |
40 |
8 |
48 |
|
| 209 |
|
| session, NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES) != 1; |
| 210 |
7960 |
▶ | inspect_window = g->ready && !g->continuation |
Branch: 1 branch
| Branch | True | False | Total |
| inspect_window = g->ready && !g->continuation |
7952 |
8 |
7960 |
|
| 211 |
16139 |
▶ | && type == NGHTTP2_WINDOW_UPDATE && frame_length == 4 && id > 0; |
Branch: 4 branches
| Branch | True | False | Total |
| && type == NGHTTP2_WINDOW_UPDATE && frame_length == 4 && id > 0; |
7960 |
219 |
8179 |
| && type == NGHTTP2_WINDOW_UPDATE && frame_length == 4 && id > 0; |
59 |
7893 |
7952 |
| && type == NGHTTP2_WINDOW_UPDATE && frame_length == 4 && id > 0; |
59 |
0 |
59 |
| && type == NGHTTP2_WINDOW_UPDATE && frame_length == 4 && id > 0; |
55 |
4 |
59 |
|
| 212 |
8179 |
▶ | need = inspect_priority ? 14 : inspect_window ? 13 : 9; |
Branch: 2 branches
| Branch | True | False | Total |
| need = inspect_priority ? 14 : inspect_window ? 13 : 9; |
8139 |
40 |
8179 |
| need = inspect_priority ? 14 : inspect_window ? 13 : 9; |
55 |
8084 |
8139 |
|
| 213 |
8179 |
▶ | if (buffered || length - offset < need) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (buffered || length - offset < need) { |
6199 |
1980 |
8179 |
| if (buffered || length - offset < need) { |
4 |
6195 |
6199 |
|
| 214 |
1984 |
▶ | if (!buffered) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!buffered) { |
4 |
1980 |
1984 |
|
| 215 |
4 |
| memcpy(g->prefix, p, 9); |
| 216 |
4 |
| g->prefix_used = 9; |
| 217 |
4 |
| offset += 9; |
| 218 |
4 |
| buffered = 1; |
| 219 |
|
| } |
| 220 |
1984 |
| n = need - g->prefix_used; |
| 221 |
1984 |
▶ | if (n > length - offset) n = length - offset; |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > length - offset) n = length - offset; |
44 |
1940 |
1984 |
|
| 222 |
1984 |
| memcpy(g->prefix + g->prefix_used, data + offset, n); |
| 223 |
1984 |
| g->prefix_used += n; |
| 224 |
1984 |
| offset += n; |
| 225 |
1984 |
▶ | if (g->prefix_used < need) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (g->prefix_used < need) break; |
44 |
1940 |
1984 |
|
| 226 |
1940 |
| p = g->prefix; |
| 227 |
|
| } |
| 228 |
|
| |
| 229 |
8135 |
▶ | if (g->ready && !g->continuation |
Branch: 2 branches
| Branch | True | False | Total |
| if (g->ready && !g->continuation |
7916 |
219 |
8135 |
| if (g->ready && !g->continuation |
7908 |
8 |
7916 |
|
| 230 |
7908 |
▶ | && frame_length <= nghttp2_session_get_local_settings( |
Branch: 1 branch
| Branch | True | False | Total |
| && frame_length <= nghttp2_session_get_local_settings( |
7900 |
8 |
7908 |
|
| 231 |
|
| session, NGHTTP2_SETTINGS_MAX_FRAME_SIZE)) { |
| 232 |
|
| /* Recent nghttp2 versions escalate stream-window overflow to a |
| 233 |
|
| * connection error. Preserve the required stream-local reset, |
| 234 |
|
| * using nghttp2's authoritative send window, without updating it. |
| 235 |
|
| * The parser is at a frame boundary: consume just this frame. |
| 236 |
|
| */ |
| 237 |
7900 |
▶ | if (inspect_window |
Branch: 1 branch
| Branch | True | False | Total |
| if (inspect_window |
35 |
7865 |
7900 |
|
| 238 |
35 |
| && (int64_t)nghttp2_session_get_stream_remote_window_size(session, id) |
| 239 |
35 |
▶ | + ub_h2_u31(p + 9) > INT32_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| + ub_h2_u31(p + 9) > INT32_MAX) { |
16 |
19 |
35 |
|
| 240 |
16 |
| rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, id, |
| 241 |
|
| NGHTTP2_FLOW_CONTROL_ERROR); |
| 242 |
16 |
▶ | if (rv != 0) return rv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != 0) return rv; |
0 |
16 |
16 |
|
| 243 |
16 |
▶ | if (!buffered) offset += 13; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!buffered) offset += 13; |
8 |
8 |
16 |
|
| 244 |
16 |
| g->prefix_used = 0; |
| 245 |
16 |
| continue; |
| 246 |
|
| } |
| 247 |
7884 |
▶ | if (inspect_priority && (!id || ub_h2_u31(p + 9) == (uint32_t)id)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (inspect_priority && (!id || ub_h2_u31(p + 9) == (uint32_t)id)) { |
16 |
7868 |
7884 |
| if (inspect_priority && (!id || ub_h2_u31(p + 9) == (uint32_t)id)) { |
8 |
8 |
16 |
| if (inspect_priority && (!id || ub_h2_u31(p + 9) == (uint32_t)id)) { |
8 |
0 |
8 |
|
| 248 |
16 |
| rv = ub_h2_reject(g, session, NGHTTP2_PROTOCOL_ERROR, |
| 249 |
|
| "invalid legacy PRIORITY stream dependency"); |
| 250 |
16 |
▶ | return rv < 0 ? rv : (ssize_t)length; |
Branch: 1 branch
| Branch | True | False | Total |
| return rv < 0 ? rv : (ssize_t)length; |
0 |
16 |
16 |
|
| 251 |
|
| } |
| 252 |
7868 |
▶ | if (type == NGHTTP2_HEADERS || type == NGHTTP2_DATA) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (type == NGHTTP2_HEADERS || type == NGHTTP2_DATA) { |
454 |
7414 |
7868 |
| if (type == NGHTTP2_HEADERS || type == NGHTTP2_DATA) { |
147 |
307 |
454 |
|
| 253 |
7561 |
| kind = ub_h2_history_kind(g, id); |
| 254 |
7561 |
▶ | if (kind == UB_H2_CLOSED || kind == UB_H2_SKIPPED) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (kind == UB_H2_CLOSED || kind == UB_H2_SKIPPED) { |
7511 |
50 |
7561 |
| if (kind == UB_H2_CLOSED || kind == UB_H2_SKIPPED) { |
16 |
7495 |
7511 |
|
| 255 |
16 |
▶ | uint32_t code = kind == UB_H2_SKIPPED && type == NGHTTP2_HEADERS |
Branch: 1 branch
| Branch | True | False | Total |
| uint32_t code = kind == UB_H2_SKIPPED && type == NGHTTP2_HEADERS |
16 |
0 |
16 |
|
| 256 |
82 |
▶ | ? NGHTTP2_PROTOCOL_ERROR : NGHTTP2_STREAM_CLOSED; |
Branch: 1 branch
| Branch | True | False | Total |
| ? NGHTTP2_PROTOCOL_ERROR : NGHTTP2_STREAM_CLOSED; |
16 |
50 |
66 |
|
| 257 |
66 |
| rv = ub_h2_reject(g, session, code, |
| 258 |
|
| "frame on closed or skipped stream"); |
| 259 |
66 |
▶ | return rv < 0 ? rv : (ssize_t)length; |
Branch: 1 branch
| Branch | True | False | Total |
| return rv < 0 ? rv : (ssize_t)length; |
0 |
66 |
66 |
|
| 260 |
|
| } |
| 261 |
|
| } |
| 262 |
|
| } |
| 263 |
|
| |
| 264 |
8037 |
▶ | g->current_rst = type == NGHTTP2_RST_STREAM && frame_length == 4 ? id : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| g->current_rst = type == NGHTTP2_RST_STREAM && frame_length == 4 ? id : 0; |
33 |
8004 |
8037 |
| g->current_rst = type == NGHTTP2_RST_STREAM && frame_length == 4 ? id : 0; |
33 |
0 |
33 |
|
| 265 |
8037 |
▶ | if (type == NGHTTP2_HEADERS && !(flags & NGHTTP2_FLAG_END_HEADERS)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (type == NGHTTP2_HEADERS && !(flags & NGHTTP2_FLAG_END_HEADERS)) |
7382 |
655 |
8037 |
| if (type == NGHTTP2_HEADERS && !(flags & NGHTTP2_FLAG_END_HEADERS)) |
8 |
7374 |
7382 |
|
| 266 |
8 |
| g->continuation = id; |
| 267 |
8029 |
▶ | else if (type == NGHTTP2_CONTINUATION && (flags & NGHTTP2_FLAG_END_HEADERS)) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (type == NGHTTP2_CONTINUATION && (flags & NGHTTP2_FLAG_END_HEADERS)) |
0 |
8029 |
8029 |
| else if (type == NGHTTP2_CONTINUATION && (flags & NGHTTP2_FLAG_END_HEADERS)) |
0 |
0 |
0 |
|
| 268 |
0 |
| g->continuation = 0; |
| 269 |
|
| |
| 270 |
8037 |
▶ | n = buffered ? need : length - offset; |
Branch: 1 branch
| Branch | True | False | Total |
| n = buffered ? need : length - offset; |
6150 |
1887 |
8037 |
|
| 271 |
8037 |
▶ | if (n > frame_length + 9) n = frame_length + 9; |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > frame_length + 9) n = frame_length + 9; |
200 |
7837 |
8037 |
|
| 272 |
8037 |
| g->payload_left = frame_length - (n - 9); |
| 273 |
8037 |
| rv = nghttp2_session_mem_recv(session, p, n); |
| 274 |
8037 |
▶ | if (rv < 0) return rv; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv < 0) return rv; |
0 |
8037 |
8037 |
|
| 275 |
8037 |
▶ | if ((size_t)rv != n) return NGHTTP2_ERR_CALLBACK_FAILURE; |
Branch: 1 branch
| Branch | True | False | Total |
| if ((size_t)rv != n) return NGHTTP2_ERR_CALLBACK_FAILURE; |
0 |
8037 |
8037 |
|
| 276 |
8037 |
▶ | if (!buffered) offset += n; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!buffered) offset += n; |
6150 |
1887 |
8037 |
|
| 277 |
8037 |
| g->prefix_used = 0; |
| 278 |
|
| } |
| 279 |
55388 |
| return (ssize_t)length; |
| 280 |
|
| } |