From 831ed285de4c5b4106c95194b7176b17b6d58550 Mon Sep 17 00:00:00 2001 From: yuuki Date: Sat, 30 Mar 2019 23:04:41 +0900 Subject: [PATCH] Fixed calculation error caused by invalid octal number "%j" format of GNU date command will be replaced a zero-padded 3 digit number. When `day-of-year < 100`, leading character of `NOWDAYS` or `ENDDAYS` is '0' and bash interprets two variables as octal. ``` $ TZ= date +%j -d 2019-03-30 089 $ echo $(( 089 )) bash: 089: value too great for base (error token is "089") ``` --- bin/ca-renew-cert | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/ca-renew-cert b/bin/ca-renew-cert index 1ca943f..282bde0 100755 --- a/bin/ca-renew-cert +++ b/bin/ca-renew-cert @@ -15,6 +15,10 @@ Options: __EOT__ } +remove_leading_zeros() { + sed 's/^0\+//' +} + short="hf:t:d:" long="help,config:,type:,days:" opts=$( getopt -o "$short" -l "$long" -n "$PROGNAME" -- "$@" ) @@ -58,10 +62,10 @@ SERIAL=$( openssl x509 -in "$CRT" -noout -serial | cut -d= -f2 ) # these dates are " " export TZ=UTC NOWYEAR=$( date +%Y ) -NOWDAYS=$( date +%j ) +NOWDAYS=$( date +%j | remove_leading_zeros ) # XXX: this only works with GNU date, BSD portability fail. ENDYEAR=$( date +%Y -d "$ENDDATE + $CA_CRT_DAYS days" ) -ENDDAYS=$( date +%j -d "$ENDDATE + $CA_CRT_DAYS days" ) +ENDDAYS=$( date +%j -d "$ENDDATE + $CA_CRT_DAYS days" | remove_leading_zeros ) CERTDATE=$( date +%Y-%m-%d -d "$ENDDATE" ) # and this does the maths to work out how many days there are from now