From owner-cvs-src-old@FreeBSD.ORG Sun Jan 10 14:30:41 2010 Return-Path: Delivered-To: cvs-src-old@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88D2A106566B for ; Sun, 10 Jan 2010 14:30:41 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 75F648FC13 for ; Sun, 10 Jan 2010 14:30:41 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o0AEUf9b069360 for ; Sun, 10 Jan 2010 14:30:41 GMT (envelope-from cperciva@repoman.freebsd.org) Received: (from svn2cvs@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o0AEUfMQ069359 for cvs-src-old@freebsd.org; Sun, 10 Jan 2010 14:30:41 GMT (envelope-from cperciva@repoman.freebsd.org) Message-Id: <201001101430.o0AEUfMQ069359@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: svn2cvs set sender to cperciva@repoman.freebsd.org using -f From: Colin Percival Date: Sun, 10 Jan 2010 14:30:30 +0000 (UTC) To: cvs-src-old@freebsd.org X-FreeBSD-CVS-Branch: HEAD Subject: cvs commit: src/lib/libc/stdio fread.c fwrite.c X-BeenThere: cvs-src-old@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: **OBSOLETE** CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jan 2010 14:30:41 -0000 cperciva 2010-01-10 14:30:30 UTC FreeBSD src repository Modified files: lib/libc/stdio fread.c fwrite.c Log: SVN rev 201999 on 2010-01-10 14:30:30Z by cperciva Give a less silly response to a silly request. Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX were handled by reading or writing (size_t)(size * nmemb) bytes; for example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1 byte and indicate that the requested 6700417 blocks had been read. This commit adds a check for such integer overflows, and treats them as if an overly large request was passed to read/write; i.e., it sets errno to EINVAL, sets the error indicator on the file, and returns a short object count (0, to be specific). The overflow check involves an integer division, so as a performance optimization we check first to see if both size and nmemb are less than 2^16; if they are, no overflow is possible and we avoid the division. We assume here that size_t is at least 32 bits; this appears to be true on all platforms FreeBSD supports. Although this commit fixes an integer overflow, it is not likely to have any security implications, since any program which would be affected by this bug fix is quite clearly already very confused. Reviewed by: kib MFC after: 1 month Revision Changes Path 1.17 +22 -1 src/lib/libc/stdio/fread.c 1.14 +18 -2 src/lib/libc/stdio/fwrite.c