Skip to content
/ linux Public

Commit f1aa813

Browse files
Jenny Guanni Qugregkh
authored andcommitted
netfilter: xt_time: use unsigned int for monthday bit shift
[ Upstream commit 00050ec ] The monthday field can be up to 31, and shifting a signed integer 1 by 31 positions (1 << 31) is undefined behavior in C, as the result overflows a 32-bit signed int. Use 1U to ensure well-defined behavior for all valid monthday values. Change the weekday shift to 1U as well for consistency. Fixes: ee4411a ("[NETFILTER]: x_tables: add xt_time match") Reported-by: Klaudia Kloc <klaudia@vidocsecurity.com> Reported-by: Dawid Moczadło <dawid@vidocsecurity.com> Tested-by: Jenny Guanni Qu <qguanni@gmail.com> Signed-off-by: Jenny Guanni Qu <qguanni@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cb54992 commit f1aa813

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/netfilter/xt_time.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
227227

228228
localtime_2(&current_time, stamp);
229229

230-
if (!(info->weekdays_match & (1 << current_time.weekday)))
230+
if (!(info->weekdays_match & (1U << current_time.weekday)))
231231
return false;
232232

233233
/* Do not spend time computing monthday if all days match anyway */
234234
if (info->monthdays_match != XT_TIME_ALL_MONTHDAYS) {
235235
localtime_3(&current_time, stamp);
236-
if (!(info->monthdays_match & (1 << current_time.monthday)))
236+
if (!(info->monthdays_match & (1U << current_time.monthday)))
237237
return false;
238238
}
239239

0 commit comments

Comments
 (0)