* libmisc/log.c: Check return values. If lseek() failed, avoid
reading or writing at an unspecified location. Log to syslog in case of failure. * libmisc/log.c: Use the right casts.
This commit is contained in:
parent
e1307ea789
commit
68cdac68cb
@ -1,3 +1,10 @@
|
|||||||
|
2008-06-15 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* libmisc/log.c: Check return values. If lseek() failed, avoid
|
||||||
|
reading or writing at an unspecified location. Log to syslog in
|
||||||
|
case of failure.
|
||||||
|
* libmisc/log.c: Use the right casts.
|
||||||
|
|
||||||
2008-06-15 Nicolas François <nicolas.francois@centraliens.net>
|
2008-06-15 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* libmisc/find_new_ids.c, libmisc/find_new_gid.c,
|
* libmisc/find_new_ids.c, libmisc/find_new_gid.c,
|
||||||
|
@ -72,7 +72,7 @@ dolastlog (struct lastlog *ll, const struct passwd *pw, const char *line,
|
|||||||
* for this UID. Negative UID's will create problems, but ...
|
* for this UID. Negative UID's will create problems, but ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
offset = (unsigned long) pw->pw_uid * sizeof newlog;
|
offset = (off_t) pw->pw_uid * sizeof newlog;
|
||||||
|
|
||||||
if (lseek (fd, offset, SEEK_SET) != offset) {
|
if (lseek (fd, offset, SEEK_SET) != offset) {
|
||||||
close (fd);
|
close (fd);
|
||||||
@ -85,7 +85,7 @@ dolastlog (struct lastlog *ll, const struct passwd *pw, const char *line,
|
|||||||
* the way we read the old one in.
|
* the way we read the old one in.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (read (fd, (char *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) {
|
if (read (fd, (void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) {
|
||||||
memzero (&newlog, sizeof newlog);
|
memzero (&newlog, sizeof newlog);
|
||||||
}
|
}
|
||||||
if (NULL != ll) {
|
if (NULL != ll) {
|
||||||
@ -99,9 +99,13 @@ dolastlog (struct lastlog *ll, const struct passwd *pw, const char *line,
|
|||||||
#if HAVE_LL_HOST
|
#if HAVE_LL_HOST
|
||||||
strncpy (newlog.ll_host, host, sizeof newlog.ll_host);
|
strncpy (newlog.ll_host, host, sizeof newlog.ll_host);
|
||||||
#endif
|
#endif
|
||||||
if (lseek (fd, offset, SEEK_SET) == offset) {
|
if ( (lseek (fd, offset, SEEK_SET) != offset)
|
||||||
write (fd, (char *) &newlog, sizeof newlog);
|
|| (write (fd, (const void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog)
|
||||||
|
|| (close (fd) != 0)) {
|
||||||
|
SYSLOG ((LOG_WARN,
|
||||||
|
"Can't write lastlog entry for UID %lu in %s.",
|
||||||
|
(unsigned long) pw->pw_uid, LASTLOG_FILE));
|
||||||
|
(void) close (fd);
|
||||||
}
|
}
|
||||||
close (fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user