Commit f7597410 by Edward Thomson

netops: safely cast to int

Only read at most INT_MAX from the underlying stream, so that we can
accurately return the number of bytes read.

Since callers are not guaranteed to get as many bytes as requested (due
to availability of input), this is safe and callers should call in a
loop until EOF.
parent cfd44d6a
......@@ -37,14 +37,17 @@ void gitno_buffer_setup_callback(
static int recv_stream(gitno_buffer *buf)
{
git_stream *io = (git_stream *) buf->cb_data;
int ret;
size_t readlen = buf->len - buf->offset;
ssize_t ret;
ret = git_stream_read(io, buf->data + buf->offset, buf->len - buf->offset);
readlen = min(readlen, INT_MAX);
ret = git_stream_read(io, buf->data + buf->offset, (int)readlen);
if (ret < 0)
return -1;
buf->offset += ret;
return ret;
return (int)ret;
}
void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data, size_t len)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment