Use time(&now) instead of now = time(NULL) when storing the current

time in a time_t (better compiler error checking).
Better parsing and printing of 64-bit time_t on 32-bit platforms.
This commit is contained in:
Todd C. Miller
2013-04-23 13:15:22 -04:00
parent 2b1b9ae72d
commit 95b50f84af
10 changed files with 42 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2012 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 2011-2013 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -381,7 +381,7 @@ sudo_debug_write_file(const char *func, const char *file, int lineno,
}
/* Do timestamp last due to ctime's static buffer. */
now = time(NULL);
time(&now);
timestr = ctime(&now) + 4;
timestr[15] = ' '; /* replace year with a space */
timestr[16] = '\0';

View File

@@ -551,6 +551,9 @@
/* Define to 1 if you have the `strsignal' function. */
#undef HAVE_STRSIGNAL
/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#undef HAVE_STRUCT_DIRENT_D_TYPE

4
configure vendored
View File

@@ -16739,8 +16739,8 @@ $as_echo "#define HAVE_GETGROUPS 1" >>confdefs.h
fi
LIBS=$ac_save_LIBS
for ac_func in glob strrchr sysconf tzset strftime setenv \
regcomp nl_langinfo
for ac_func in glob nl_langinfo regcomp setenv strftime strrchr strtoll \
sysconf tzset
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@@ -2229,9 +2229,8 @@ dnl
dnl Function checks
dnl
AC_FUNC_GETGROUPS
AC_CHECK_FUNCS(glob strrchr sysconf tzset strftime setenv \
regcomp nl_langinfo)
dnl AC_REPLACE_FUNCS(getgrouplist)
AC_CHECK_FUNCS(glob nl_langinfo regcomp setenv strftime strrchr strtoll \
sysconf tzset)
AC_CHECK_FUNCS(getgrouplist, [], [
case "$host_os" in
aix*)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2011 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -63,7 +63,7 @@
int
get_boottime(struct timeval *tv)
{
char *line = NULL;
char *ep, *line = NULL;
size_t linesize = 0;
ssize_t len;
FILE * fp;
@@ -74,9 +74,21 @@ get_boottime(struct timeval *tv)
if (fp != NULL) {
while ((len = getline(&line, &linesize, fp)) != -1) {
if (strncmp(line, "btime ", 6) == 0) {
tv->tv_sec = atoi(line + 6);
tv->tv_usec = 0;
debug_return_bool(1);
#ifdef HAVE_STRTOLL
long long llval = strtoll(line + 6, &ep, 10);
if (line[6] != '\0' && *ep == '\0' && (time_t)llval == llval) {
tv->tv_sec = (time_t)llval;
tv->tv_usec = 0;
debug_return_bool(1);
}
#else
long lval = strtol(line + 6, &ep, 10);
if (line[6] != '\0' && *ep == '\0' && (time_t)lval == lval) {
tv->tv_sec = (time_t)llval;
tv->tv_usec = 0;
debug_return_bool(1);
}
#endif
}
}
fclose(fp);

View File

@@ -592,8 +592,8 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
}
gettimeofday(&last_time, NULL);
fprintf(io_log_files[IOFD_LOG].fd.f, "%ld:%s:%s:%s:%s:%d:%d\n%s\n%s",
(long)last_time.tv_sec,
fprintf(io_log_files[IOFD_LOG].fd.f, "%lld:%s:%s:%s:%s:%d:%d\n%s\n%s",
(long long)last_time.tv_sec,
details.user ? details.user : "unknown", details.runas_pw->pw_name,
details.runas_gr ? details.runas_gr->gr_name : "",
details.tty ? details.tty : "unknown", details.lines, details.cols,

View File

@@ -2096,12 +2096,12 @@ sudo_ldap_set_options_conn(LDAP *ld)
struct timeval tv;
tv.tv_sec = ldap_conf.timeout;
tv.tv_usec = 0;
DPRINTF(("ldap_set_option(LDAP_OPT_TIMEOUT, %ld)",
(long)tv.tv_sec), 1);
DPRINTF(("ldap_set_option(LDAP_OPT_TIMEOUT, %d)",
ldap_conf.timeout), 1);
rc = ldap_set_option(ld, LDAP_OPT_TIMEOUT, &tv);
if (rc != LDAP_OPT_SUCCESS) {
warningx("ldap_set_option(TIMEOUT, %ld): %s",
(long)tv.tv_sec, ldap_err2string(rc));
warningx("ldap_set_option(TIMEOUT, %d): %s",
ldap_conf.timeout, ldap_err2string(rc));
}
}
#endif
@@ -2111,14 +2111,14 @@ sudo_ldap_set_options_conn(LDAP *ld)
struct timeval tv;
tv.tv_sec = ldap_conf.bind_timelimit / 1000;
tv.tv_usec = 0;
DPRINTF(("ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT, %ld)",
(long)tv.tv_sec), 1);
DPRINTF(("ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT, %d)",
ldap_conf.bind_timelimit / 1000), 1);
rc = ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &tv);
# if !defined(LDAP_OPT_CONNECT_TIMEOUT) || LDAP_VENDOR_VERSION != 510
/* Tivoli Directory Server 6.3 libs always return a (bogus) error. */
if (rc != LDAP_OPT_SUCCESS) {
warningx("ldap_set_option(NETWORK_TIMEOUT, %ld): %s",
(long)tv.tv_sec, ldap_err2string(rc));
warningx("ldap_set_option(NETWORK_TIMEOUT, %d): %s",
ldap_conf.bind_timelimit / 1000, ldap_err2string(rc));
}
# endif
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994-1996, 1998-2012 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 1994-1996, 1998-2013 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -197,7 +197,7 @@ do_logfile(char *msg)
send_mail(_("unable to lock log file: %s: %s"),
def_logfile, strerror(errno));
} else {
now = time(NULL);
time(&now);
if (def_loglinelen < sizeof(LOG_INDENT)) {
/* Don't pretty-print long log file lines (hard to grep) */
if (def_log_host)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 Todd C. Miller <Todd.Miller@courtesan.com>
* Copyright (c) 2009-2013 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -525,8 +525,8 @@ delay(double secs)
rval = nanosleep(&ts, &rts);
} while (rval == -1 && errno == EINTR);
if (rval == -1) {
fatal_nodebug(_("nanosleep: tv_sec %ld, tv_nsec %ld"),
(long)ts.tv_sec, (long)ts.tv_nsec);
fatal_nodebug(_("nanosleep: tv_sec %lld, tv_nsec %ld"),
(long long)ts.tv_sec, (long)ts.tv_nsec);
}
}

View File

@@ -340,7 +340,7 @@ timestamp_status_internal(bool removing)
if (def_timestamp_timeout < 0) {
status = TS_CURRENT;
} else {
now = time(NULL);
time(&now);
if (def_timestamp_timeout &&
now - mtime.tv_sec < 60 * def_timestamp_timeout) {
/*