These calls were intending to copy from a NUL-padded (possibly
non-NUL-terminated) character sequences contained in fixed-width arrays,
into a string, where extra padding is superfluous. Use the appropriate
call, which removes the superfluous work. That reduces the chance of
confusing maintainers about the intention of the code.
While at it, use the appropriate third parameter, which is the size of
the source buffer, and not the one of the destination buffer. As a side
effect, this reduces the use of '-1', which itself reduces the chance of
off-by-one bugs.
Also, since using sizeof() on an array is dangerous, use SIZEOF_ARRAY().
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
#include "alloc.h"
#include "sizeof.h"
+#include "zustr2stp.h"
#ident "$Id$"
#ifdef HAVE_STRUCT_UTMP_UT_HOST
} else if ( (NULL != ut)
&& ('\0' != ut->ut_host[0])) {
- hostname = XMALLOC(sizeof(ut->ut_host) + 1, char);
- strncpy (hostname, ut->ut_host, sizeof (ut->ut_host));
- hostname[sizeof (ut->ut_host)] = '\0';
+ hostname = XMALLOC(SIZEOF_ARRAY(ut->ut_host) + 1, char);
+ zustr2stp(hostname, ut->ut_host, SIZEOF_ARRAY(ut->ut_host));
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
}
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
+#include "sizeof.h"
+#include "zustr2stp.h"
/*
* Global variables
*/
char user[sizeof (ut->ut_user) + 1];
time_t now;
- /*
- * ut_user may not have the terminating NUL.
- */
- strncpy (user, ut->ut_user, sizeof (ut->ut_user));
- user[sizeof (ut->ut_user)] = '\0';
+ zustr2stp(user, ut->ut_user, SIZEOF_ARRAY(ut->ut_user));
(void) time (&now);
kill (-ut->ut_pid, SIGKILL);
}
- strncpy (user, ut->ut_user, sizeof (user) - 1);
- user[sizeof (user) - 1] = '\0';
+ zustr2stp(user, ut->ut_user, SIZEOF_ARRAY(ut->ut_user));
SYSLOG ((LOG_NOTICE,
"logged off user '%s' on '%s'", user,