hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 58f4416a8ecfeeed550b78531226b203130db7a8
parent caa76ac3182a30fa96f7e75482c3574a72afd1e5
Author: Lorenz (xha) <me@xha.li>
Date:   Wed,  1 Nov 2023 16:51:35 +0100

io: return errors::invalid if len(vectors): int overflows

Signed-off-by: Lorenz (xha) <lorenz@xha.li>

Diffstat:
Mio/+freebsd/vector.ha | 8++++++--
Mio/+linux/vector.ha | 8++++++--
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/io/+freebsd/vector.ha b/io/+freebsd/vector.ha @@ -17,7 +17,9 @@ export fn mkvector(buf: []u8) vector = vector { // the vectors, prepared with [[mkvector]], in order, and the total number of // bytes read is returned. export fn readv(fd: file, vectors: vector...) (size | EOF | error) = { - assert(len(vectors) <= types::INT_MAX: size); + if (len(vectors) > types::INT_MAX: size) { + return errors::invalid; + }; match (rt::readv(fd, vectors: *[*]rt::iovec, len(vectors): int)) { case let err: rt::errno => return errors::errno(err); @@ -35,7 +37,9 @@ export fn readv(fd: file, vectors: vector...) (size | EOF | error) = { // with [[mkvector]], are written to the file in order, and the total number of // bytes written is returned. export fn writev(fd: file, vectors: vector...) (size | error) = { - assert(len(vectors) <= types::INT_MAX: size); + if (len(vectors) > types::INT_MAX: size) { + return errors::invalid; + }; match (rt::writev(fd, vectors: *[*]rt::iovec, len(vectors): int)) { case let err: rt::errno => return errors::errno(err); diff --git a/io/+linux/vector.ha b/io/+linux/vector.ha @@ -17,7 +17,9 @@ export fn mkvector(buf: []u8) vector = vector { // the vectors, prepared with [[mkvector]], in order, and the total number of // bytes read is returned. export fn readv(fd: file, vectors: vector...) (size | EOF | error) = { - assert(len(vectors) <= types::INT_MAX: size); + if (len(vectors) > types::INT_MAX: size) { + return errors::invalid; + }; match (rt::readv(fd, vectors: *[*]rt::iovec, len(vectors): int)) { case let err: rt::errno => return errors::errno(err); @@ -35,7 +37,9 @@ export fn readv(fd: file, vectors: vector...) (size | EOF | error) = { // with [[mkvector]], are written to the file in order, and the total number of // bytes written is returned. export fn writev(fd: file, vectors: vector...) (size | error) = { - assert(len(vectors) <= types::INT_MAX: size); + if (len(vectors) > types::INT_MAX: size) { + return errors::invalid; + }; match (rt::writev(fd, vectors: *[*]rt::iovec, len(vectors): int)) { case let err: rt::errno => return errors::errno(err);