From owner-freebsd-bugs@FreeBSD.ORG Mon Jul 5 12:30:23 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 79BC916A4CE for ; Mon, 5 Jul 2004 12:30:23 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 55E1943D41 for ; Mon, 5 Jul 2004 12:30:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i65CUN1r072139 for ; Mon, 5 Jul 2004 12:30:23 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i65CUNEv072138; Mon, 5 Jul 2004 12:30:23 GMT (envelope-from gnats) Resent-Date: Mon, 5 Jul 2004 12:30:23 GMT Resent-Message-Id: <200407051230.i65CUNEv072138@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, KOIE Hidetaka Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 66B8816A4CE for ; Mon, 5 Jul 2004 12:21:13 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5EE9E43D3F for ; Mon, 5 Jul 2004 12:21:13 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i65CLCOo057711 for ; Mon, 5 Jul 2004 12:21:12 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i65CLC3Q057710; Mon, 5 Jul 2004 12:21:12 GMT (envelope-from nobody) Message-Id: <200407051221.i65CLC3Q057710@www.freebsd.org> Date: Mon, 5 Jul 2004 12:21:12 GMT From: KOIE Hidetaka To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: kern/68690: write(2) returns wrong vlalue when EFAULT X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2004 12:30:23 -0000 >Number: 68690 >Category: kern >Synopsis: write(2) returns wrong vlalue when EFAULT >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jul 05 12:30:22 GMT 2004 >Closed-Date: >Last-Modified: >Originator: KOIE Hidetaka >Release: FreeBSD-5.2 CURRENT >Organization: SURIGIKEN >Environment: FreeBSD sakura.suri.co.jp 5.2-CURRENT FreeBSD 5.2-CURRENT #1: Tue Jun 15 11:43:02 JST 2004 koie@sakura.suri.co.jp:/usr/obj/usr/src/sys/SAKURA i386 >Description: Invoking write(fd, buf, size), if buf has both validand invalid segment, write return -1, but it's file pointer has been advanced. The caller mistakes the pointer stays. >How-To-Repeat: #include #include #include #include #include #include int main() { const int PAGESIZE = sysconf(_SC_PAGESIZE); const int N = 5; const int SIZE = N * PAGESIZE; int ifd = open("in.dat", O_RDWR|O_CREAT|O_TRUNC, 0600); if (ifd < 0) { perror("open"); goto out; } int should = 0; for (int i = 0; i < N - 2; i++) { char buf[PAGESIZE]; if (write(ifd, buf, sizeof buf) != sizeof buf) { perror("write"); goto out; } should += sizeof buf; } int ofd = open("out.dat", O_WRONLY|O_CREAT|O_TRUNC, 0600); if (ofd < 0) { perror("open"); goto out; } void *addr = mmap(0, SIZE, PROT_READ, MAP_PRIVATE, ifd, 0); if (addr == MAP_FAILED) { perror("mmap"); goto out; } fprintf(stderr, "pos=%ld\n", (long)lseek(ofd, 0, SEEK_CUR)); int n = write(ofd, addr, SIZE); fprintf(stderr, "write(%d)->%d (should be %d)\n", SIZE, n, should); perror("write"); fprintf(stderr, "pos=%ld (should be %d)\n", (long)lseek(ofd, 0, SEEK_CUR), should); out: exit(0); } >Fix: Sorry, I don't know. >Release-Note: >Audit-Trail: >Unformatted: