diff options
author | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2019-05-02 08:30:11 +0000 |
---|---|---|
committer | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2019-05-02 08:30:11 +0000 |
commit | 539f7f68170ee7d97ea14badd96ddaf247d21852 (patch) | |
tree | 7660520c55e17b7020cef16dd7c6138a99a7e026 /lib/libc | |
parent | a4c0c9da3ed51a8a3aa38b0994f808a830ece96d (diff) |
Fix a comparison in open_memstream not to confuse when a negative
value is given for the off. found by nagasaka at IIJ.
ok deraadt
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/open_memstream.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c index 131d4e08e13..6ee5a5c2794 100644 --- a/lib/libc/stdio/open_memstream.c +++ b/lib/libc/stdio/open_memstream.c @@ -1,4 +1,4 @@ -/* $OpenBSD: open_memstream.c,v 1.7 2017/03/17 14:53:08 deraadt Exp $ */ +/* $OpenBSD: open_memstream.c,v 1.8 2019/05/02 08:30:10 yasuoka Exp $ */ /* * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> @@ -76,7 +76,7 @@ static fpos_t memstream_seek(void *v, fpos_t off, int whence) { struct state *st = v; - ssize_t base = 0; + size_t base = 0; switch (whence) { case SEEK_SET: @@ -89,7 +89,7 @@ memstream_seek(void *v, fpos_t off, int whence) break; } - if (off > SIZE_MAX - base || off < -base) { + if ((off > 0 && off > SIZE_MAX - base) || (off < 0 && base < -off)) { errno = EOVERFLOW; return (-1); } |