Skip site navigation (1)Skip section navigation (2)
Date:      28 Oct 2002 22:22:03 -0500
From:      Lowell Gilbert <freebsd-stable-local@be-well.no-ip.com>
To:        "Charles Swiger" <cswiger@mac.com>
Cc:        <freebsd-stable@FreeBSD.ORG>, <bryanf@samurai.com>
Subject:   Re: last cores
Message-ID:  <44lm4i7wv8.fsf@be-well.ilk.org>
In-Reply-To: <000701c27ecd$4ba3d9e0$0301a8c0@prime>
References:  <A9ED2106-EABA-11D6-916A-000393013B04@samurai.com> <44smyq9r4m.fsf@be-well.ilk.org> <000701c27ecd$4ba3d9e0$0301a8c0@prime>

next in thread | previous in thread | raw e-mail | index | archive | help
"Charles Swiger" <cswiger@mac.com> writes:

> From: "Lowell Gilbert" <freebsd-security-local@be-well.no-ip.com>
> > Bryan Fullerton <bryanf@samurai.com> writes:
> >> Someone might want to look at this.
> >>
> >> % last -w0
> >> Segmentation fault (core dumped)
> >>
> >> Does this on 4.6.2-RELEASE-p2, 4.7-RELEASE, 4.7-STABLE (Oct 17).
> >
> > Doesn't belong the -security list, but it looks like the
> > backward-compatibility hack in the option-handling switch
> > statement of last.c needs another hack.
> 
> The example in the getopt(3) manpage should probably be reviewed for
> correctness as well.  Bryan, please see whether this helps:
> 
> 5-sec# diff -w -c last.c_orig last.c
> /usr/src/usr.bin/last
> *** last.c_orig Mon Oct 28 08:41:16 2002
> --- last.c      Mon Oct 28 09:10:18 2002
> ***************
> *** 142,147 ****
> --- 143,149 ----
>                          * a number after a dash.
>                          */
>                         if (maxrec == -1) {
> +                               if (optind == argc) break;
>                                 p = argv[optind - 1];
>                                 if (p[0] == '-' && p[1] == ch && !p[2])
>                                         maxrec = atol(++p);
> 

This is still a serious hack (I'm not sure how else you can get into
this case, but the code obviously thinks there's another way), but it
at least shouldn't be broken for any cases that the original wasn't,
and it fixes the specific one reported:

*** /usr/src/usr.bin/last/last.c        Tue Mar 12 15:09:29 2002
--- last.c      Mon Oct 28 22:20:55 2002
***************
*** 145,151 ****
                                p = argv[optind - 1];
                                if (p[0] == '-' && p[1] == ch && !p[2])
                                        maxrec = atol(++p);
!                               else
                                        maxrec = atol(argv[optind] + 1);
                                if (!maxrec)
                                        exit(0);
--- 145,151 ----
                                p = argv[optind - 1];
                                if (p[0] == '-' && p[1] == ch && !p[2])
                                        maxrec = atol(++p);
!                               else if (argv[optind])
                                          maxrec = atol(argv[optind] + 1);
                                if (!maxrec)
                                        exit(0);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44lm4i7wv8.fsf>