When the "compat" method is specified in the nsswitch.conf file, special entries containing the "+" or "-" characters are allowed to be used in the /etc/passwd file. Previously, when the finger utility was run with a "username" argument on a host that had the special entries in /etc/passwd, finger terminated with a segmentation fault. With this update, the code that handles the "username" argument has been fixed to perform the necessary checks and the finger utility no longer crashes in the described scenario.
DescriptionLars Kellogg-Stedman
2012-04-25 19:49:36 UTC
Description of problem:
We have a NIS-bound system with 'passwd: compat' in /etc/nsswitch.conf. The final line in /etc/passwd on this was system was:
+:
On this system, "finger" would segfault when passed a username as an
argument. On line 188 in finger/util.c, finger was calling strncpy()
like this:
int
match(struct passwd *pw, const char *user)
{
char *p;
int i, j, ct, rv=0;
char *rname;
strncpy(tbuf, pw->pw_gecos, TBUFLEN);
With our /etc/passwd file configured as described, pw->pw_gecos would
have a NULL rather than empty value, causing strncpy() to segfault.
An ideal fix would be to have match() return 0 if pw->pw_gecos is
NULL, as in this patch:
diff --git a/finger/util.c b/finger/util.c
index 8e28d63..c82bc86 100644
--- a/finger/util.c
+++ b/finger/util.c
@@ -186,6 +186,9 @@ match(struct passwd *pw, const char *user)
int i, j, ct, rv=0;
char *rname;
+ if (pw->pw_gecos == NULL)
+ return 0;
+
strncpy(tbuf, pw->pw_gecos, TBUFLEN);
tbuf[TBUFLEN-1] = 0; /* guarantee null termination */
p = tbuf;
Comment 3Lars Kellogg-Stedman
2012-10-11 13:02:30 UTC
Problem identified and patch provided...any updates on this issue? Thanks!
(In reply to Lars Kellogg-Stedman from comment #3)
> Problem identified and patch provided...any updates on this issue? Thanks!
Hi Lars.
If everything goes well, this issue will be fixed in the next RHEL-6 minor
update release.
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
http://rhn.redhat.com/errata/RHBA-2014-0587.html
Description of problem: We have a NIS-bound system with 'passwd: compat' in /etc/nsswitch.conf. The final line in /etc/passwd on this was system was: +: On this system, "finger" would segfault when passed a username as an argument. On line 188 in finger/util.c, finger was calling strncpy() like this: int match(struct passwd *pw, const char *user) { char *p; int i, j, ct, rv=0; char *rname; strncpy(tbuf, pw->pw_gecos, TBUFLEN); With our /etc/passwd file configured as described, pw->pw_gecos would have a NULL rather than empty value, causing strncpy() to segfault. An ideal fix would be to have match() return 0 if pw->pw_gecos is NULL, as in this patch: diff --git a/finger/util.c b/finger/util.c index 8e28d63..c82bc86 100644 --- a/finger/util.c +++ b/finger/util.c @@ -186,6 +186,9 @@ match(struct passwd *pw, const char *user) int i, j, ct, rv=0; char *rname; + if (pw->pw_gecos == NULL) + return 0; + strncpy(tbuf, pw->pw_gecos, TBUFLEN); tbuf[TBUFLEN-1] = 0; /* guarantee null termination */ p = tbuf;