CID 348324: Integer handling issue (OVERFLOW_BEFORE_WIDEN) in /lib/dns/time.c
*** CID 348324: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
/lib/dns/time.c: 184 in dns_time64_fromtext()
178 /*
179 * Calculate seconds from epoch.
180 * Note: this uses a idealized calendar.
181 */
182 value = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400);
183 for (i = 0; i < (month - 1); i++) {
>>> CID 348324: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
>>> Potentially overflowing expression "days[i] * 86400" with type "int" (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "int64_t" (64 bits, signed).
184 value += days[i] * 86400;
185 }
186 if (is_leap(year) && month > 2) {
187 value += 86400;
188 }
189 if (year < 1970) {
IIUC this is a false positive, because days
being a hard-coded const
array, with any value of days[i]
the expression days[i] * 86400
can not overflow 32 bits integer. Anyway, I think adding an INSIST
to check the value of days[i]
being in the expected range should be an acceptable solution.