[PATCH] last: Always terminate domain with '\0'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux