mirror of
https://github.com/troglobit/finit.git
synced 2026-10-14 10:19:36 +00:00
Use safe string copy using strlcpy()
Fixes issues with buffers not being NUL terminated properly. Found by Coverity Scan. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
c3adf3bf51
commit
8cfd11c909
1 file changed
+6
-6
+6
-6
@@ -49,13 +49,13 @@ int utmp_set(int type, int pid, char *line, char *id, char *user)
|
||||
ut.ut_type = type;
|
||||
ut.ut_pid = pid;
|
||||
if (user)
|
||||
strncpy(ut.ut_user, user, sizeof(ut.ut_user));
|
||||
strlcpy(ut.ut_user, user, sizeof(ut.ut_user));
|
||||
if (line)
|
||||
strncpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
if (id)
|
||||
strncpy(ut.ut_id, id, sizeof(ut.ut_id));
|
||||
strlcpy(ut.ut_id, id, sizeof(ut.ut_id));
|
||||
if (!uname(&uts))
|
||||
strncpy(ut.ut_host, uts.release, sizeof(ut.ut_host));
|
||||
strlcpy(ut.ut_host, uts.release, sizeof(ut.ut_host));
|
||||
ut.ut_tv.tv_sec = time(NULL);
|
||||
|
||||
setutent();
|
||||
@@ -141,10 +141,10 @@ int utmp_show(char *file)
|
||||
char addr[64];
|
||||
|
||||
memset(id, 0, sizeof(id));
|
||||
strncpy(id, ut->ut_id, sizeof(ut->ut_id));
|
||||
strlcpy(id, ut->ut_id, sizeof(ut->ut_id));
|
||||
|
||||
memset(user, 0, sizeof(user));
|
||||
strncpy(user, ut->ut_user, sizeof(ut->ut_user));
|
||||
strlcpy(user, ut->ut_user, sizeof(ut->ut_user));
|
||||
|
||||
sec = ut->ut_tv.tv_sec;
|
||||
sectm = localtime(&sec);
|
||||
|
||||
Reference in new issue
Block a user