All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: util-linux@vger.kernel.org
Subject: [PATCH] last: Always terminate domain with '\0'
Date: Sun, 12 Mar 2017 17:51:00 +0100	[thread overview]
Message-ID: <20170312165059.GC28165@localhost> (raw)

Although in a practical sense, the stack will most likely be filled
with zeros when the function is called, the C language requires an
explicit '\0' termination which strncat() does not guarantee.

While at it, I replaced strncat with strncpy because that's what the
program logic wants to do here.
---
 login-utils/last.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 340705757..ddbdd84a3 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -507,8 +507,8 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
 	if (r < 0) {
 		len = sizeof(p->ut_host);
 		if (len >= (int)sizeof(domain)) len = sizeof(domain) - 1;
-		domain[0] = 0;
-		strncat(domain, p->ut_host, len);
+		strncpy(domain, p->ut_host, len);
+		domain[len] = 0;
 	}
 
 
-- 
2.12.0


             reply	other threads:[~2017-03-12 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 16:51 Tobias Stoeckmann [this message]
2017-03-13 12:10 ` [PATCH] last: Always terminate domain with '\0' Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170312165059.GC28165@localhost \
    --to=tobias@stoeckmann.org \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.