Skip to content

Commit 4947216

Browse files
committed
git transport: only write INT_MAX bytes
The transport code returns an `int` with the number of bytes written; thus only attempt to write at most `INT_MAX`.
1 parent a861839 commit 4947216

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/transports/git.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
7575

7676
static int send_command(git_proto_stream *s)
7777
{
78-
int error;
7978
git_buf request = GIT_BUF_INIT;
79+
size_t write_size;
80+
int error;
8081

8182
error = gen_proto(&request, s->cmd, s->url);
8283
if (error < 0)
8384
goto cleanup;
8485

85-
error = git_stream_write(s->io, request.ptr, request.size, 0);
86+
write_size = min(request.size, INT_MAX);
87+
error = (int)git_stream_write(s->io, request.ptr, write_size, 0);
88+
8689
if (error >= 0)
8790
s->sent_command = 1;
8891

@@ -119,15 +122,16 @@ static int git_proto_stream_read(
119122
static int git_proto_stream_write(
120123
git_smart_subtransport_stream *stream,
121124
const char *buffer,
122-
size_t len)
125+
size_t buffer_len)
123126
{
124-
int error;
125127
git_proto_stream *s = (git_proto_stream *)stream;
128+
size_t len = min(buffer_len, INT_MAX);
129+
int error;
126130

127131
if (!s->sent_command && (error = send_command(s)) < 0)
128132
return error;
129133

130-
return git_stream_write(s->io, buffer, len, 0);
134+
return (int)git_stream_write(s->io, buffer, len, 0);
131135
}
132136

133137
static void git_proto_stream_free(git_smart_subtransport_stream *stream)

0 commit comments

Comments
 (0)