diff options
| author | lukem <lukem@NetBSD.org> | 2009-02-11 23:48:17 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 2009-02-11 23:48:17 +0000 |
| commit | cfd7bc04514dffe07d131c04dac540c09306ca7b (patch) | |
| tree | 2e6b3b7ec813f17fdfdc1299535631ec51b31f5e /lib/libc/stdio | |
| parent | e6e201ff78d24fd4f664209b4602268fd4291101 (diff) | |
Fix sign-compare issues.
Ensure provided uio_resid >= 0; negative sizes have "interesting"
semantics elsewhere in stdio, so it's better to avoid them.
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/fvwrite.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 54411475dcd..e938c15400e 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.17 2007/02/02 23:00:28 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.18 2009/02/11 23:48:17 lukem Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.17 2007/02/02 23:00:28 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.18 2009/02/11 23:48:17 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -61,7 +61,7 @@ __sfvwrite(fp, uio) FILE *fp; struct __suio *uio; { - size_t len; + int len; char *p; struct __siov *iov; int w, s; @@ -71,6 +71,10 @@ __sfvwrite(fp, uio) _DIAGASSERT(fp != NULL); _DIAGASSERT(uio != NULL); + if ((int)uio->uio_resid < 0) { + errno = EINVAL; + return (EOF); + } if ((len = uio->uio_resid) == 0) return (0); /* make sure we can write */ @@ -122,7 +126,7 @@ __sfvwrite(fp, uio) GETIOV(;); if ((fp->_flags & (__SALC | __SSTR)) == (__SALC | __SSTR) && fp->_w < len) { - size_t blen = fp->_p - fp->_bf._base; + int blen = fp->_p - fp->_bf._base; unsigned char *_base; int _size; @@ -183,7 +187,7 @@ __sfvwrite(fp, uio) do { GETIOV(nlknown = 0); if (!nlknown) { - nl = memchr((void *)p, '\n', len); + nl = memchr((void *)p, '\n', (size_t)len); nldist = nl ? nl + 1 - p : len + 1; nlknown = 1; } |
