AIX usrinfo() cleanup.
Ben Lindstrom
mouring at etoh.eviladmin.org
Fri Jul 5 03:51:48 EST 2002
On Thu, 4 Jul 2002, Gert Doering wrote:
> Hi,
>
> On Thu, Jul 04, 2002 at 10:41:20AM -0500, troy wrote:
> > > - cp = xmalloc(22 + strlen(tty) + 2 * strlen(pw->pw_name));
> > > - i = sprintf(cp, "LOGNAME=%s%cNAME=%s%cTTY=%s%c%c", pw->pw_name, 0,
> > > - pw->pw_name, 0, tty, 0, 0);
> > > + cp = xmalloc(16 + 2 * strlen(pw->pw_name));
> > > + i = sprintf(cp, "LOGNAME=%s%cNAME=%s%c%c", pw->pw_name, 0,
> > > + pw->pw_name, 0, 0);
> >
> > Doesn't sprintf add a trailing NULL to the end? Don't you need to
> > xmalloc(16+2*strlen(pw->pw_name)+1)?
>
> Indeed. The new string is 5 (plus strlen(tty)) characters shorter, not 6.
>
The other question that I was going to ask was why are we putting 3 \0 at
the end of the string?
- Ben
More information about the openssh-unix-dev
mailing list