NetBSD Problem Report #51867
From www@NetBSD.org Sat Jan 14 01:54:43 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 51A877A227
for <gnats-bugs@gnats.NetBSD.org>; Sat, 14 Jan 2017 01:54:43 +0000 (UTC)
Message-Id: <20170114015442.276277A2A2@mollari.NetBSD.org>
Date: Sat, 14 Jan 2017 01:54:42 +0000 (UTC)
From: yaneurabeya@gmail.com
Reply-To: yaneurabeya@gmail.com
To: gnats-bugs@NetBSD.org
Subject: [PATCH] tests/lib/libc/sys/t_msync: various fixes in msync_sync(..)
X-Send-Pr-Version: www-1.0
>Number: 51867
>Category: bin
>Synopsis: [PATCH] tests/lib/libc/sys/t_msync: various fixes in msync_sync(..)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jan 14 01:55:00 +0000 2017
>Closed-Date: Sun Jan 15 20:16:39 +0000 2017
>Last-Modified: Sun Jan 15 20:16:39 +0000 2017
>Originator: Ngie Cooper
>Release: 7.0.2
>Organization:
>Environment:
n/a
>Description:
The attached patch...
- ... fixes a leak (buf) if open fails.
- ... replaces for-loop setting values with memset use.
- ... writes a series `tot` 'x''s instead of just one 'x' in a loop `tot` times.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/51867: [PATCH] tests/lib/libc/sys/t_msync: various fixes in
msync_sync(..)
Date: Fri, 13 Jan 2017 17:56:10 -0800
--Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
Patch attached.
-Ngie
--Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28
Content-Disposition: attachment;
filename=t_msync-simplify-msync_sync-through-write-and-memset.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="t_msync-simplify-msync_sync-through-write-and-memset.patch"
Content-Transfer-Encoding: 7bit
Index: lib/libc/sys/t_msync.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/sys/t_msync.c,v
retrieving revision 1.2
diff -u -r1.2 t_msync.c
--- lib/libc/sys/t_msync.c 16 Mar 2012 06:15:17 -0000 1.2
+++ lib/libc/sys/t_msync.c 13 Jan 2017 06:34:07 -0000
@@ -52,8 +52,7 @@
{
char *buf, *map = MAP_FAILED;
const char *str = NULL;
- size_t i, len;
- ssize_t tot;
+ size_t len;
int fd, rv;
/*
@@ -65,29 +64,17 @@
if (buf == NULL)
return NULL;
- for (i = 0; i < (size_t)page; i++)
- buf[i] = 'x';
+ memset(buf, 'x', page);
fd = open(path, O_RDWR | O_CREAT, 0700);
if (fd < 0) {
- str = "failed to open";
- goto out;
+ free(buf);
+ return "failed to open";
}
- tot = 0;
-
- while (tot < page) {
-
- rv = write(fd, buf, sizeof(buf));
-
- if (rv < 0) {
- str = "failed to write";
- goto out;
- }
-
- tot += rv;
- }
+ ATF_REQUIRE_MSG(write(fd, buf, page) != -1, "write(2) failed: %s",
+ strerror(errno));
map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE,
fd, 0);
--Apple-Mail=_00CC6283-06D7-4A47-98C6-3EAAA3A56E28--
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51867 CVS commit: src/tests/lib/libc/sys
Date: Sat, 14 Jan 2017 15:52:42 -0500
Module Name: src
Committed By: christos
Date: Sat Jan 14 20:52:42 UTC 2017
Modified Files:
src/tests/lib/libc/sys: t_msync.c
Log Message:
PR/51867: Ngie Cooper: misc cleanups
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_msync.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: snj@NetBSD.org
State-Changed-When: Sun, 15 Jan 2017 20:16:39 +0000
State-Changed-Why:
christos committed it. thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.