1From 09f489c89c826293ff8cbd282cfc866ab56054c4 Mon Sep 17 00:00:00 2001 2From: Laszlo Varady <laszlo.varady@protonmail.com> 3Date: Sat, 20 Aug 2022 14:29:43 +0200 4Subject: [PATCH 6/8] timeutils: name repeating constant 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9CVE: CVE-2022-38725 10 11Upstream-Status: Backport 12[https://github.com/syslog-ng/syslog-ng/commit/09f489c89c826293ff8cbd282cfc866ab56054c4] 13 14Signed-off-by: László Várady <laszlo.varady@protonmail.com> 15 16Signed-off-by: Yogita Urade <yogita.urade@windriver.com> 17--- 18 lib/timeutils/scan-timestamp.c | 54 ++++++++++++++++++---------------- 19 1 file changed, 29 insertions(+), 25 deletions(-) 20 21diff --git a/lib/timeutils/scan-timestamp.c b/lib/timeutils/scan-timestamp.c 22index 4fbe94a36..d22d50973 100644 23--- a/lib/timeutils/scan-timestamp.c 24+++ b/lib/timeutils/scan-timestamp.c 25@@ -34,41 +34,43 @@ scan_day_abbrev(const gchar **buf, gint *left, gint *wday) 26 { 27 *wday = -1; 28 29- if (*left < 3) 30+ const gsize abbrev_length = 3; 31+ 32+ if (*left < abbrev_length) 33 return FALSE; 34 35 switch (**buf) 36 { 37 case 'S': 38- if (strncasecmp(*buf, "Sun", 3) == 0) 39+ if (strncasecmp(*buf, "Sun", abbrev_length) == 0) 40 *wday = 0; 41- else if (strncasecmp(*buf, "Sat", 3) == 0) 42+ else if (strncasecmp(*buf, "Sat", abbrev_length) == 0) 43 *wday = 6; 44 else 45 return FALSE; 46 break; 47 case 'M': 48- if (strncasecmp(*buf, "Mon", 3) == 0) 49+ if (strncasecmp(*buf, "Mon", abbrev_length) == 0) 50 *wday = 1; 51 else 52 return FALSE; 53 break; 54 case 'T': 55- if (strncasecmp(*buf, "Tue", 3) == 0) 56+ if (strncasecmp(*buf, "Tue", abbrev_length) == 0) 57 *wday = 2; 58- else if (strncasecmp(*buf, "Thu", 3) == 0) 59+ else if (strncasecmp(*buf, "Thu", abbrev_length) == 0) 60 *wday = 4; 61 else 62 return FALSE; 63 break; 64 case 'W': 65- if (strncasecmp(*buf, "Wed", 3) == 0) 66+ if (strncasecmp(*buf, "Wed", abbrev_length) == 0) 67 *wday = 3; 68 else 69 return FALSE; 70 break; 71 case 'F': 72- if (strncasecmp(*buf, "Fri", 3) == 0) 73+ if (strncasecmp(*buf, "Fri", abbrev_length) == 0) 74 *wday = 5; 75 else 76 return FALSE; 77@@ -77,8 +79,8 @@ scan_day_abbrev(const gchar **buf, gint *left, gint *wday) 78 return FALSE; 79 } 80 81- (*buf) += 3; 82- (*left) -= 3; 83+ (*buf) += abbrev_length; 84+ (*left) -= abbrev_length; 85 return TRUE; 86 } 87 88@@ -87,63 +89,65 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon) 89 { 90 *mon = -1; 91 92- if (*left < 3) 93+ const gsize abbrev_length = 3; 94+ 95+ if (*left < abbrev_length) 96 return FALSE; 97 98 switch (**buf) 99 { 100 case 'J': 101- if (strncasecmp(*buf, "Jan", 3) == 0) 102+ if (strncasecmp(*buf, "Jan", abbrev_length) == 0) 103 *mon = 0; 104- else if (strncasecmp(*buf, "Jun", 3) == 0) 105+ else if (strncasecmp(*buf, "Jun", abbrev_length) == 0) 106 *mon = 5; 107- else if (strncasecmp(*buf, "Jul", 3) == 0) 108+ else if (strncasecmp(*buf, "Jul", abbrev_length) == 0) 109 *mon = 6; 110 else 111 return FALSE; 112 break; 113 case 'F': 114- if (strncasecmp(*buf, "Feb", 3) == 0) 115+ if (strncasecmp(*buf, "Feb", abbrev_length) == 0) 116 *mon = 1; 117 else 118 return FALSE; 119 break; 120 case 'M': 121- if (strncasecmp(*buf, "Mar", 3) == 0) 122+ if (strncasecmp(*buf, "Mar", abbrev_length) == 0) 123 *mon = 2; 124- else if (strncasecmp(*buf, "May", 3) == 0) 125+ else if (strncasecmp(*buf, "May", abbrev_length) == 0) 126 *mon = 4; 127 else 128 return FALSE; 129 break; 130 case 'A': 131- if (strncasecmp(*buf, "Apr", 3) == 0) 132+ if (strncasecmp(*buf, "Apr", abbrev_length) == 0) 133 *mon = 3; 134- else if (strncasecmp(*buf, "Aug", 3) == 0) 135+ else if (strncasecmp(*buf, "Aug", abbrev_length) == 0) 136 *mon = 7; 137 else 138 return FALSE; 139 break; 140 case 'S': 141- if (strncasecmp(*buf, "Sep", 3) == 0) 142+ if (strncasecmp(*buf, "Sep", abbrev_length) == 0) 143 *mon = 8; 144 else 145 return FALSE; 146 break; 147 case 'O': 148- if (strncasecmp(*buf, "Oct", 3) == 0) 149+ if (strncasecmp(*buf, "Oct", abbrev_length) == 0) 150 *mon = 9; 151 else 152 return FALSE; 153 break; 154 case 'N': 155- if (strncasecmp(*buf, "Nov", 3) == 0) 156+ if (strncasecmp(*buf, "Nov", abbrev_length) == 0) 157 *mon = 10; 158 else 159 return FALSE; 160 break; 161 case 'D': 162- if (strncasecmp(*buf, "Dec", 3) == 0) 163+ if (strncasecmp(*buf, "Dec", abbrev_length) == 0) 164 *mon = 11; 165 else 166 return FALSE; 167@@ -152,8 +156,8 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon) 168 return FALSE; 169 } 170 171- (*buf) += 3; 172- (*left) -= 3; 173+ (*buf) += abbrev_length; 174+ (*left) -= abbrev_length; 175 return TRUE; 176 } 177 178-- 1792.34.1 180 181