NetBSD Problem Report #24070
Received: (qmail 10052 invoked by uid 605); 12 Jan 2004 19:41:33 -0000
Message-Id: <20040112194130.3BCEE11155@narn.netbsd.org>
Date: Mon, 12 Jan 2004 19:41:30 +0000 (UTC)
From: Todd.Miller@courtesan.com
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: Todd.Miller@courtesan.com
To: gnats-bugs@gnats.NetBSD.org
Subject: moduser uses fgetln() incorrectly
X-Send-Pr-Version: www-1.0
>Number: 24070
>Category: bin
>Synopsis: moduser uses fgetln() incorrectly
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: agc
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 12 19:42:00 +0000 2004
>Closed-Date: Wed Jan 14 08:27:33 +0000 2004
>Last-Modified: Wed Jan 14 08:27:33 +0000 2004
>Originator: Todd Miller
>Release: -current
>Organization:
OpenBSD
>Environment:
I don't run NetBSD...
>Description:
moduser() in usr.sbin/user.c uses the string returned by fgetln() as if it is a NUL-terminated string but it is not. For instance, if a passwd file entry were to contain no ':' then strchr() would go past the end of the string. A similar problem exists with the strncmp() when comparing a very long username to a very short (possibly corrupt) passwd entry. Also, there is an unneeded cast of asprintf() to int (len used to be int but no longer is).
>How-To-Repeat:
inspect the code...
>Fix:
Either use fgets() instead of fgetln() or use memchr() instead of strchr() and MIN(colonc, loginc) as the length parameter to strncmp() (and perhaps consider using memcmp() instead). In OpenBSD I just switched to fgets() for consistency with the rest of the code.
>Release-Note:
>Audit-Trail:
From: "Alistair G. Crooks" <agc@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: pr/24070 CVS commit: src/usr.sbin/user
Date: Wed, 14 Jan 2004 08:25:30 +0000 (UTC)
Module Name: src
Committed By: agc
Date: Wed Jan 14 08:25:30 UTC 2004
Modified Files:
src/usr.sbin/user: user.c
Log Message:
Fixes from Todd Miller in PR 24070.
Revert fgetln/asprintf changes from rev 1.26 - fgetln(3) does not return
a NUL-terminated string, so using strchr(3) is inappropriate. As the entry
from the password file is a known size, there's no need to use fgetln(3),
just use fgets(3) for consistency. This also means that an inappropriate
cast to int from asprintf(3) is unneeded, which was apparently causing
problems on OpenBSD's sparc64 port - just be consistent and use snprintf(3).
To generate a diff of this commit:
cvs rdiff -r1.73 -r1.74 src/usr.sbin/user/user.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: agc
State-Changed-When: Wed Jan 14 08:26:51 UTC 2004
State-Changed-Why:
The fixes from the PR were applied - thanks for pointing them out.
Responsible-Changed-From-To: bin-bug-people->agc
Responsible-Changed-By: agc
Responsible-Changed-When: Wed Jan 14 08:26:51 UTC 2004
Responsible-Changed-Why:
agc took responsibility for this one.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.