Skip to content

Commit 4718ecd

Browse files
committed
Fix another integer narrowing warning.
* buckets/http2_frame_buckets.c (serf__bucket_http2_frame_create): Change the max_payload_size argument from an apr_uint32_t to an apr_size_t, because that's how we store it in our internal data structures. Move the size check to the beginning of the function so that we can never use a payload size that's too large. * protocols/http2_buckets.h (serf__bucket_http2_frame_create): Update the prototype. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1927634 13f79535-47bb-0310-9956-ffa450edef68
1 parent a1556ca commit 4718ecd

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

buckets/http2_frame_buckets.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -630,22 +630,24 @@ serf__bucket_http2_frame_create(serf_bucket_t *stream,
630630
void *baton,
631631
apr_int32_t *stream_id),
632632
void *stream_id_baton,
633-
apr_uint32_t max_payload_size,
633+
apr_size_t max_payload_size,
634634
serf_bucket_alloc_t *alloc)
635635
{
636-
serf_http2_frame_context_t *ctx = serf_bucket_mem_alloc(alloc,
637-
sizeof(*ctx));
636+
serf_http2_frame_context_t *ctx;
638637

638+
/* The upper limit for HTTP/2 MAX_FRAME_SIZE is 16 MiB - 1.
639+
https://www.rfc-editor.org/rfc/rfc9113.html#section-4.2 */
640+
if (max_payload_size > 0xFFFFFF)
641+
max_payload_size = 0xFFFFFF;
642+
643+
ctx = serf_bucket_mem_alloc(alloc, sizeof(*ctx));
639644
ctx->alloc = alloc;
640645
ctx->stream = stream;
641646
ctx->chunk = serf_bucket_aggregate_create(alloc);
642647
ctx->max_payload_size = max_payload_size;
643648
ctx->frametype = frame_type;
644649
ctx->flags = flags;
645650

646-
if (max_payload_size > 0xFFFFFF)
647-
max_payload_size = 0xFFFFFF;
648-
649651
if (!stream_id_alloc || (stream_id && *stream_id >= 0))
650652
{
651653
/* Avoid all alloc handling; we know the final id */
@@ -980,4 +982,3 @@ const serf_bucket_type_t serf_bucket_type__http2_frame =
980982
serf_http2_frame_get_remaining,
981983
serf_http2_frame_set_config
982984
};
983-

protocols/http2_buckets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ serf__bucket_http2_frame_create(serf_bucket_t *stream,
202202
void *baton,
203203
apr_int32_t *stream_id),
204204
void *stream_id_baton,
205-
apr_uint32_t max_payload_size,
205+
apr_size_t max_payload_size,
206206
serf_bucket_alloc_t *alloc);
207207

208208
/* ==================================================================== */

0 commit comments

Comments
 (0)