From 9e3eeadeb3120f3577e00ab9cb410eccf8d71de0 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sep 29 2015 13:16:09 +0000 Subject: Fix an integer underflow bug in libotp Temporarily storing the offset time in an unsigned integer causes the value of the offset to underflow when a (valid) negative offset value is generated. Using a signed variable avoids this problem. https://fedorahosted.org/freeipa/ticket/5333 Reviewed-By: Tomas Babej --- diff --git a/daemons/ipa-slapi-plugins/libotp/otp_token.c b/daemons/ipa-slapi-plugins/libotp/otp_token.c index 9b90c6a..a3cbfb0 100644 --- a/daemons/ipa-slapi-plugins/libotp/otp_token.c +++ b/daemons/ipa-slapi-plugins/libotp/otp_token.c @@ -199,10 +199,10 @@ static bool validate(struct otp_token *token, time_t now, ssize_t step, case TYPE_TOTP: /* Perform optional synchronization steps. */ if (second != NULL) { - tmp = (step - now / token->totp.step) * token->totp.step; - if (!writeattr(token, T("clockOffset"), tmp)) + long long off = (step - now / token->totp.step) * token->totp.step; + if (!writeattr(token, T("clockOffset"), off)) return false; - token->totp.offset = tmp; + token->totp.offset = off; } token->totp.watermark = step; break;