From: Todd C. Miller Date: Sat, 20 Jul 2019 02:14:44 +0000 (-0600) Subject: Use strftime(3) instead of formatting struct tm by hand. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e424640b9dde5b61cd3ab4d2352d11f19efb0fb;p=sudo Use strftime(3) instead of formatting struct tm by hand. Fixes a warning on newer versions of gcc. --- diff --git a/configure b/configure index b9634e651..bf591dac7 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for sudo 1.8.28. +# Generated by GNU Autoconf 2.69 for sudo 1.8.28b1. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='sudo' PACKAGE_TARNAME='sudo' -PACKAGE_VERSION='1.8.28' -PACKAGE_STRING='sudo 1.8.28' +PACKAGE_VERSION='1.8.28b1' +PACKAGE_STRING='sudo 1.8.28b1' PACKAGE_BUGREPORT='https://bugzilla.sudo.ws/' PACKAGE_URL='' @@ -1543,7 +1543,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sudo 1.8.28 to adapt to many kinds of systems. +\`configure' configures sudo 1.8.28b1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1608,7 +1608,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sudo 1.8.28:";; + short | recursive ) echo "Configuration of sudo 1.8.28b1:";; esac cat <<\_ACEOF @@ -1874,7 +1874,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sudo configure 1.8.28 +sudo configure 1.8.28b1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2583,7 +2583,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sudo $as_me 1.8.28, which was +It was created by sudo $as_me 1.8.28b1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -27506,7 +27506,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sudo $as_me 1.8.28, which was +This file was extended by sudo $as_me 1.8.28b1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -27572,7 +27572,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -sudo config.status 1.8.28 +sudo config.status 1.8.28b1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 65b145049..e4055e26d 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. dnl AC_PREREQ([2.59]) -AC_INIT([sudo], [1.8.28], [https://bugzilla.sudo.ws/], [sudo]) +AC_INIT([sudo], [1.8.28b1], [https://bugzilla.sudo.ws/], [sudo]) AC_CONFIG_HEADER([config.h pathnames.h]) AC_CONFIG_SRCDIR([src/sudo.c]) dnl diff --git a/plugins/sudoers/fmtsudoers.c b/plugins/sudoers/fmtsudoers.c index 0827e363c..c93281f71 100644 --- a/plugins/sudoers/fmtsudoers.c +++ b/plugins/sudoers/fmtsudoers.c @@ -237,18 +237,14 @@ sudoers_format_cmndspec(struct sudo_lbuf *lbuf, if (cs->notbefore != UNSPEC && FIELD_CHANGED(prev_cs, cs, notbefore)) { char buf[sizeof("CCYYMMDDHHMMSSZ")]; struct tm *tm = gmtime(&cs->notbefore); - (void)snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - sudo_lbuf_append(lbuf, "NOTBEFORE=%s ", buf); + if (strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", tm) != 0) + sudo_lbuf_append(lbuf, "NOTBEFORE=%s ", buf); } if (cs->notafter != UNSPEC && FIELD_CHANGED(prev_cs, cs, notafter)) { char buf[sizeof("CCYYMMDDHHMMSSZ")]; struct tm *tm = gmtime(&cs->notafter); - (void)snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - sudo_lbuf_append(lbuf, "NOTAFTER=%s ", buf); + if (strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", tm) != 0) + sudo_lbuf_append(lbuf, "NOTAFTER=%s ", buf); } if (TAG_CHANGED(prev_cs, cs, tags, setenv)) sudo_lbuf_append(lbuf, tags.setenv ? "SETENV: " : "NOSETENV: "); diff --git a/plugins/sudoers/parse.c b/plugins/sudoers/parse.c index 4cea829e9..3a41330a6 100644 --- a/plugins/sudoers/parse.c +++ b/plugins/sudoers/parse.c @@ -517,20 +517,14 @@ display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw, if (cs->notbefore != UNSPEC) { char buf[sizeof("CCYYMMDDHHMMSSZ")]; struct tm *tm = gmtime(&cs->notbefore); - (void)snprintf(buf, sizeof(buf), - "%04d%02d%02d%02d%02d%02dZ", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - sudo_lbuf_append(lbuf, " NotBefore: %s\n", buf); + if (strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", tm) != 0) + sudo_lbuf_append(lbuf, " NotBefore: %s\n", buf); } if (cs->notafter != UNSPEC) { char buf[sizeof("CCYYMMDDHHMMSSZ")]; struct tm *tm = gmtime(&cs->notafter); - (void)snprintf(buf, sizeof(buf), - "%04d%02d%02d%02d%02d%02dZ", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - sudo_lbuf_append(lbuf, " NotAfter: %s\n", buf); + if (strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", tm) != 0) + sudo_lbuf_append(lbuf, " NotAfter: %s\n", buf); } sudo_lbuf_append(lbuf, _(" Commands:\n")); }