NetBSD Problem Report #51808
From www@NetBSD.org Tue Jan 10 09:17:41 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 0B6DB7A26E
for <gnats-bugs@gnats.NetBSD.org>; Tue, 10 Jan 2017 09:17:41 +0000 (UTC)
Message-Id: <20170110091740.28F6D7A2AF@mollari.NetBSD.org>
Date: Tue, 10 Jan 2017 09:17:40 +0000 (UTC)
From: yaneurabeya@gmail.com
Reply-To: yaneurabeya@gmail.com
To: gnats-bugs@NetBSD.org
Subject: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity issues
X-Send-Pr-Version: www-1.0
>Number: 51808
>Category: bin
>Synopsis: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity issues
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jan 10 09:20:00 +0000 2017
>Closed-Date: Tue Jan 10 18:15:13 +0000 2017
>Last-Modified: Wed Jan 11 09:05:01 +0000 2017
>Originator: Ngie Cooper
>Release: 7.0.2
>Organization:
>Environment:
n/a
>Description:
Fix various coverity issues:
- Don't leak memory.
- Check results of creat(2), mkdir(2), and telldir(3).
While here, sort #includes.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity
issues
Date: Tue, 10 Jan 2017 01:20:30 -0800
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
Patch attached.
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A
Content-Disposition: attachment;
filename=t_dir-fix-coverity-issues.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="t_dir-fix-coverity-issues.patch"
Content-Transfer-Encoding: 7bit
Index: t_dir.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/gen/t_dir.c,v
retrieving revision 1.6
diff -u -r1.6 t_dir.c
--- t_dir.c 19 Oct 2013 17:45:00 -0000 1.6
+++ t_dir.c 10 Jan 2017 09:16:18 -0000
@@ -26,18 +26,19 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <atf-c.h>
-
+#include <sys/stat.h>
#include <assert.h>
+#include <atf-c.h>
#include <dirent.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <sys/stat.h>
+
ATF_TC(seekdir_basic);
ATF_TC_HEAD(seekdir_basic, tc)
@@ -54,10 +55,19 @@
struct dirent *entry;
long here;
- mkdir("t", 0755);
- creat("t/a", 0600);
- creat("t/b", 0600);
- creat("t/c", 0600);
+#define CREAT(x, m) do { \
+ int _creat_fd; \
+ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))), \
+ "creat(%s, %x) failed: %s", (x), (m), \
+ strerror(errno)); \
+ (void)close(_creat_fd); \
+ } while(0);
+
+ ATF_REQUIRE_MSG(mkdir("t", 0755) == 0,
+ "mkdir failed: %s", strerror(errno));
+ CREAT("t/a", 0600);
+ CREAT("t/b", 0600);
+ CREAT("t/c", 0600);
dp = opendir("t");
if ( dp == NULL)
@@ -70,6 +80,8 @@
/* get first entry */
entry = readdir(dp);
here = telldir(dp);
+ ATF_REQUIRE_MSG(here != -1,
+ "telldir failed: %s", strerror(errno));
/* get second entry */
entry = readdir(dp);
@@ -109,6 +121,7 @@
atf_tc_fail("3rd seekdir found wrong name");
closedir(dp);
+ free(wasname);
}
ATF_TC(telldir_leak);
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A--
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51808 CVS commit: src/tests/lib/libc/gen
Date: Tue, 10 Jan 2017 10:19:00 -0500
Module Name: src
Committed By: christos
Date: Tue Jan 10 15:19:00 UTC 2017
Modified Files:
src/tests/lib/libc/gen: t_dir.c
Log Message:
PR/51808: Ngie Cooper: fix leaks, sort includes, check returns
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/t_dir.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: dholland@NetBSD.org
State-Changed-When: Tue, 10 Jan 2017 18:15:13 +0000
State-Changed-Why:
christos committed it, thanks
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity
issues
Date: Tue, 10 Jan 2017 23:11:10 -0800
--Apple-Mail=_D5AF5B24-B98B-45A9-951C-736BB1D6B3AC
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
I goofed up the CREAT macro a bit =E2=80=94 it should be checking for a =
return code not equal to -1, not a non-zero exit code =E2=80=94 sorry =
:/=E2=80=A6
-Ngie
--Apple-Mail=_D5AF5B24-B98B-45A9-951C-736BB1D6B3AC
Content-Disposition: attachment;
filename=fix-CREAT-macro-added-in-1_7.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="fix-CREAT-macro-added-in-1_7.patch"
Content-Transfer-Encoding: 7bit
Index: t_dir.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/gen/t_dir.c,v
retrieving revision 1.7
diff -u -r1.7 t_dir.c
--- t_dir.c 10 Jan 2017 15:19:00 -0000 1.7
+++ t_dir.c 11 Jan 2017 07:07:46 -0000
@@ -55,12 +55,12 @@
struct dirent *entry;
long here;
-#define CREAT(x, m) do { \
- int _creat_fd; \
- ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))), \
- "creat(%s, %x) failed: %s", (x), (m), \
- strerror(errno)); \
- (void)close(_creat_fd); \
+#define CREAT(x, m) do { \
+ int _creat_fd; \
+ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m)) != -1), \
+ "creat(%s, %x) failed: %s", (x), (m), \
+ strerror(errno)); \
+ (void)close(_creat_fd); \
} while(0);
ATF_REQUIRE_MSG(mkdir("t", 0755) == 0,
--Apple-Mail=_D5AF5B24-B98B-45A9-951C-736BB1D6B3AC--
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
yaneurabeya@gmail.com
Cc:
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity issues
Date: Wed, 11 Jan 2017 02:26:35 -0500
On Jan 11, 7:15am, yaneurabeya@gmail.com ("Ngie Cooper (yaneurabeya)") wrote:
-- Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various cove
| I goofed up the CREAT macro a bit =E2=80=94 it should be checking for a =
| return code not equal to -1, not a non-zero exit code =E2=80=94 sorry =
| :/=E2=80=A6
| -Ngie
Got it.
christos
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity
issues
Date: Wed, 11 Jan 2017 00:35:49 -0800
--Apple-Mail=_794D7605-18E0-44E5-B0FA-FD8BF22BBD2C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
Dangit. I did it properly on FreeBSD, but screwed up when I =
submitted the patch for NetBSD. The -1 should be outside the parentheses =
in CREAT :=E2=80=99(.
I think this is my cue to step away from the keyboard for a bit=E2=80=A6
-Ngie
-bash-4.4$ cvs diff -u t_dir.c=20
Index: t_dir.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/tests/lib/libc/gen/t_dir.c,v
retrieving revision 1.8
diff -u -r1.8 t_dir.c
--- t_dir.c 11 Jan 2017 07:26:17 -0000 1.8
+++ t_dir.c 11 Jan 2017 08:35:23 -0000
@@ -57,7 +57,7 @@
=20
#define CREAT(x, m) do { =
\
int _creat_fd; =
\
- ATF_REQUIRE_MSG((_creat_fd =3D creat((x), (m)) !=3D -1), =
\
+ ATF_REQUIRE_MSG((_creat_fd =3D creat((x), (m))) !=3D -1, =
\
"creat(%s, %x) failed: %s", (x), (m), =
\
strerror(errno)); =
\
(void)close(_creat_fd); =
\=
--Apple-Mail=_794D7605-18E0-44E5-B0FA-FD8BF22BBD2C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=utf-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" =
class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
</span>Dangit. I did it properly on FreeBSD, but screwed up when I =
submitted the patch for NetBSD. The -1 should be outside the parentheses =
in CREAT :=E2=80=99(.<div class=3D"">I think this is my cue to step away =
from the keyboard for a bit=E2=80=A6</div><div class=3D"">-Ngie<br =
class=3D""><div class=3D""><br class=3D""></div><div class=3D""><div =
style=3D"margin: 0px; line-height: normal; font-family: 'Andale Mono'; =
color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D"">-bash-4.4$ cvs diff -u t_dir.c </span></div><div =
style=3D"margin: 0px; line-height: normal; font-family: 'Andale Mono'; =
color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D"">Index: t_dir.c</span></div><div style=3D"margin: 0px; =
line-height: normal; font-family: 'Andale Mono'; color: rgb(40, 254, =
20); background-color: rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D"">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</span></di=
v><div style=3D"margin: 0px; line-height: normal; font-family: 'Andale =
Mono'; color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, =
0.901961);" class=3D""><span style=3D"font-variant-ligatures: =
no-common-ligatures" class=3D"">RCS file: =
/cvsroot/src/tests/lib/libc/gen/t_dir.c,v</span></div><div =
style=3D"margin: 0px; line-height: normal; font-family: 'Andale Mono'; =
color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D"">retrieving revision 1.8</span></div><div style=3D"margin: =
0px; line-height: normal; font-family: 'Andale Mono'; color: rgb(40, =
254, 20); background-color: rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D"">diff -u =
-r1.8 t_dir.c</span></div><div style=3D"margin: 0px; line-height: =
normal; font-family: 'Andale Mono'; color: rgb(40, 254, 20); =
background-color: rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D"">--- =
t_dir.c 11 Jan 2017 07:26:17 -0000 =
1.8</span></div><div style=3D"margin: 0px; line-height: normal; =
font-family: 'Andale Mono'; color: rgb(40, 254, 20); background-color: =
rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D"">+++ =
t_dir.c 11 Jan 2017 08:35:23 -0000</span></div><div =
style=3D"margin: 0px; line-height: normal; font-family: 'Andale Mono'; =
color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D"">@@ -57,7 +57,7 @@</span></div><p style=3D"margin: 0px; =
line-height: normal; font-family: 'Andale Mono'; color: rgb(40, 254, =
20); background-color: rgba(0, 0, 0, 0.901961); min-height: 14px;" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D""> </span><br class=3D"webkit-block-placeholder"></p><div =
style=3D"margin: 0px; line-height: normal; font-family: 'Andale Mono'; =
color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" =
class=3D""><span style=3D"font-variant-ligatures: no-common-ligatures" =
class=3D""> #define CREAT(x, m) =
do { =
=
\</span></div><div style=3D"margin: 0px; =
line-height: normal; font-family: 'Andale Mono'; color: rgb(40, 254, =
20); background-color: rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D""> =
int _creat_fd; =
=
=
\</span></div><div style=3D"margin: 0px; line-height: normal; =
font-family: 'Andale Mono'; color: rgb(40, 254, 20); background-color: =
rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D"">- =
=
ATF_REQUIRE_MSG((_creat_fd =3D creat((x), (m)) !=3D -1), =
\</span></div><div style=3D"margin: 0px; line-height: normal; =
font-family: 'Andale Mono'; color: rgb(40, 254, 20); background-color: =
rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D"">+ =
=
ATF_REQUIRE_MSG((_creat_fd =3D creat((x), (m))) !=3D -1, =
\</span></div><div style=3D"margin: 0px; line-height: normal; =
font-family: 'Andale Mono'; color: rgb(40, 254, 20); background-color: =
rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D""> =
=
"creat(%s, %x) failed: %s", (x), (m), =
\</span></div><div style=3D"margin: 0px; line-height: =
normal; font-family: 'Andale Mono'; color: rgb(40, 254, 20); =
background-color: rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D""> =
=
strerror(errno)); =
=
\</span></div><div style=3D"margin: 0px; line-height: normal; =
font-family: 'Andale Mono'; color: rgb(40, 254, 20); background-color: =
rgba(0, 0, 0, 0.901961);" class=3D""><span =
style=3D"font-variant-ligatures: no-common-ligatures" class=3D""> =
(void)close(_creat_fd); =
=
=
\</span></div></div></div></body></html>=
--Apple-Mail=_794D7605-18E0-44E5-B0FA-FD8BF22BBD2C--
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity
issues
Date: Wed, 11 Jan 2017 00:59:55 -0800
--Apple-Mail=_C3310D0C-92A0-4EFF-A753-AAF8944721E1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
I guess it=E2=80=99s for the better that I forgot =E2=80=94 I didn=E2=80=99=
t include a check for readdir returning NULL that I had added on FreeBSD =
to address another Coverity issue (I just wish I had gotten this on try =
# 2).
-Ngie
--Apple-Mail=_C3310D0C-92A0-4EFF-A753-AAF8944721E1
Content-Disposition: attachment;
filename=t_dir-last-bit-of-fixes.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="t_dir-last-bit-of-fixes.patch"
Content-Transfer-Encoding: 7bit
Index: t_dir.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/gen/t_dir.c,v
retrieving revision 1.8
diff -u -r1.8 t_dir.c
--- t_dir.c 11 Jan 2017 07:26:17 -0000 1.8
+++ t_dir.c 11 Jan 2017 08:59:27 -0000
@@ -57,7 +57,7 @@
#define CREAT(x, m) do { \
int _creat_fd; \
- ATF_REQUIRE_MSG((_creat_fd = creat((x), (m)) != -1), \
+ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \
"creat(%s, %x) failed: %s", (x), (m), \
strerror(errno)); \
(void)close(_creat_fd); \
@@ -91,6 +91,8 @@
/* get third entry */
entry = readdir(dp);
+ ATF_REQUIRE_MSG(entry != NULL,
+ "readdir failed: %s", strerror(errno));
/* try to return to the position after the first entry */
seekdir(dp, here);
--Apple-Mail=_C3310D0C-92A0-4EFF-A753-AAF8944721E1--
>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.