(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-mail/message-date.c) |
| |
| 110 | | | message_date_parser_tokens(struct message_date_parser_context *ctx, |
| 111 | | | time_t *timestamp_r, int *timezone_offset_r) |
| 112 | | | { |
| 113 | | | struct tm tm; |
| 114 | | | const unsigned char *value; |
| 115 | | | size_t i, len; |
| 116 | | | int ret; |
| 117 | | | |
| 118 | | | |
| 119 | | | memset(&tm, 0, sizeof(tm)); |
| 120 | | | |
| 121 | | | (void)rfc822_skip_lwsp(&ctx->parser); |
| 122 | | | |
| 123 | | | |
| 124 | | | if (next_token(ctx, &value, &len) <= 0) |
Redundant Condition
next_token(...) <= 0 always evaluates to true. This may be because: - There is a constant assignment to one or more of the variables involved.
- An earlier conditional statement has already ensured that next_token(...) <= 0 cannot be false.
- A crashing bug occurs on every path where next_token(...) <= 0 could have evaluated to false. Look for a preceding Null Pointer Dereference or Division By Zero warning.
|
|
| 125 | | | return FALSE; |
| 126 | | | if (len == 3) { |
| 127 | | | if (*ctx->parser.data != ',') |
| 128 | | | return FALSE; |
| 129 | | | ctx->parser.data++; |
| 130 | | | (void)rfc822_skip_lwsp(&ctx->parser); |
| 131 | | | |
| 132 | | | if (next_token(ctx, &value, &len) <= 0) |
| 133 | | | return FALSE; |
| 134 | | | } |
| 135 | | | |
| 136 | | | |
| 137 | | | if (len < 1 || len > 2 || !i_isdigit(value[0])) |
| 138 | | | return FALSE; |
| 139 | | | |
| 140 | | | tm.tm_mday = value[0]-'0'; |
| 141 | | | if (len == 2) { |
| 142 | | | if (!i_isdigit(value[1])) |
| 143 | | | return FALSE; |
| 144 | | | tm.tm_mday = (tm.tm_mday * 10) + (value[1]-'0'); |
| 145 | | | } |
| 146 | | | |
| 147 | | | |
| 148 | | | if (next_token(ctx, &value, &len) <= 0 || len < 3) |
| 149 | | | return FALSE; |
| 150 | | | |
| 151 | | | for (i = 0; i < 12; i++) { |
| 152 | | | if (i_memcasecmp(month_names[i], value, 3) == 0) { |
| 153 | | | tm.tm_mon = i; |
| 154 | | | break; |
| 155 | | | } |
| 156 | | | } |
| 157 | | | if (i == 12) |
| 158 | | | return FALSE; |
| 159 | | | |
| 160 | | | |
| 161 | | | if (next_token(ctx, &value, &len) <= 0 || (len != 2 && len != 4)) |
| 162 | | | return FALSE; |
| 163 | | | |
| 164 | | | for (i = 0; i < len; i++) { |
| 165 | | | if (!i_isdigit(value[i])) |
| 166 | | | return FALSE; |
| 167 | | | tm.tm_year = tm.tm_year * 10 + (value[i]-'0'); |
| 168 | | | } |
| 169 | | | |
| 170 | | | if (len == 2) { |
| 171 | | | |
| 172 | | | if (tm.tm_year < 70) |
| 173 | | | tm.tm_year += 100; |
| 174 | | | } else { |
| 175 | | | if (tm.tm_year < 1900) |
| 176 | | | return FALSE; |
| 177 | | | tm.tm_year -= 1900; |
| 178 | | | } |
| 179 | | | |
| 180 | | | |
| 181 | | | if (next_token(ctx, &value, &len) <= 0 || |
| 182 | | | len < 1 || len > 2 || !i_isdigit(value[0])) |
| 183 | | | return FALSE; |
| 184 | | | tm.tm_hour = value[0]-'0'; |
| 185 | | | if (len == 2) { |
| 186 | | | if (!i_isdigit(value[1])) |
| 187 | | | return FALSE; |
| 188 | | | tm.tm_hour = tm.tm_hour * 10 + (value[1]-'0'); |
| 189 | | | } |
| 190 | | | |
| 191 | | | |
| 192 | | | if (*ctx->parser.data != ':') |
| 193 | | | return FALSE; |
| 194 | | | ctx->parser.data++; |
| 195 | | | (void)rfc822_skip_lwsp(&ctx->parser); |
| 196 | | | |
| 197 | | | if (next_token(ctx, &value, &len) < 0 || len != 2 || |
| 198 | | | !i_isdigit(value[0]) || !i_isdigit(value[1])) |
| 199 | | | return FALSE; |
| 200 | | | tm.tm_min = (value[0]-'0') * 10 + (value[1]-'0'); |
| 201 | | | |
| 202 | | | |
| 203 | | | if (ctx->parser.data != ctx->parser.end && *ctx->parser.data == ':') { |
| 204 | | | ctx->parser.data++; |
| 205 | | | (void)rfc822_skip_lwsp(&ctx->parser); |
| 206 | | | |
| 207 | | | if (next_token(ctx, &value, &len) <= 0 || len != 2 || |
| 208 | | | !i_isdigit(value[0]) || !i_isdigit(value[1])) |
| 209 | | | return FALSE; |
| 210 | | | tm.tm_sec = (value[0]-'0') * 10 + (value[1]-'0'); |
| 211 | | | } |
| 212 | | | |
| 213 | | | if ((ret = next_token(ctx, &value, &len)) < 0) |
| 214 | | | return FALSE; |
| 215 | | | if (ret == 0) { |
| 216 | | | |
| 217 | | | *timezone_offset_r = 0; |
| 218 | | | } else { |
| 219 | | | |
| 220 | | | *timezone_offset_r = parse_timezone(value, len); |
| 221 | | | } |
| 222 | | | |
| 223 | | | tm.tm_isdst = -1; |
| 224 | | | *timestamp_r = utc_mktime(&tm); |
| 225 | | | if (*timestamp_r == (time_t)-1) |
| 226 | | | return FALSE; |
| 227 | | | |
| 228 | | | *timestamp_r -= *timezone_offset_r * 60; |
| 229 | | | |
| 230 | | | return TRUE; |
| 231 | | | } |
| |