* off-by-one issues in login-utils
@ 2014-11-22 7:34 Joshua Rogers
2014-11-23 19:52 ` Ángel González
0 siblings, 1 reply; 2+ messages in thread
From: Joshua Rogers @ 2014-11-22 7:34 UTC (permalink / raw)
To: util-linux
[-- Attachment #1: Type: text/plain, Size: 588 bytes --]
Hi,
I've noticed a few off-by-one issues in login-utils..
login.c:963: strncpy(ut.ut_user, username, sizeof(ut.ut_user));
It should be sizeof(ut.ut_user) - 1.
Or, something like
ut.ut_user[sizeof(ut.ut_user) -1] = '\0';
And on line 275:
memset(&ut, 0, sizeof(ut));
strncpy(ut.ut_user, username ? username : "(unknown)",
sizeof(ut.ut_user));
I can't see anywhere that adds the final NUL-byte to ut.ut_user.
If I've missed something though, feel free to ignore this.
Thanks,
--
-- Joshua Rogers <https://internot.info/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: off-by-one issues in login-utils
2014-11-22 7:34 off-by-one issues in login-utils Joshua Rogers
@ 2014-11-23 19:52 ` Ángel González
0 siblings, 0 replies; 2+ messages in thread
From: Ángel González @ 2014-11-23 19:52 UTC (permalink / raw)
To: Joshua Rogers; +Cc: util-linux
On 22/11/14 08:34, Joshua Rogers wrote:
> Hi,
>
> I've noticed a few off-by-one issues in login-utils..
>
> login.c:963: strncpy(ut.ut_user, username, sizeof(ut.ut_user));
> It should be sizeof(ut.ut_user) - 1.
> Or, something like
> ut.ut_user[sizeof(ut.ut_user) -1] = '\0';
>
>
> And on line 275:
>
> memset(&ut, 0, sizeof(ut));
>
> strncpy(ut.ut_user, username ? username : "(unknown)",
> sizeof(ut.ut_user));
>
> I can't see anywhere that adds the final NUL-byte to ut.ut_user.
> If I've missed something though, feel free to ignore this.
>
> Thanks,
It's not needed. The reader of utmp(5) shall read up to
sizeof(ut.ut_user) bytes.
From utmp(5):
> String fields are terminated by a null byte ('\0') if they are
> shorter than the size of the field.
Thus it is allowed to have non-NUL-terminated fields on the file.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-23 20:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-22 7:34 off-by-one issues in login-utils Joshua Rogers
2014-11-23 19:52 ` Ángel González
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).