Skip to content
Snippets Groups Projects
Commit 4043664d authored by Timur Safin's avatar Timur Safin Committed by Igor Munkin
Browse files

datetime: fix strptime for fuzzer

Google fuzzing efforts revealed yet another bound condition
we don't handle well in the `tnt_strptime` function:

- for format `%m%g%W`;
- and input string `07001`.

We failed with assertion failure:
```
  | datetime_strptime_fuzzer: ./src/lib/core/datetime.c:148: \
_Bool tm_to_datetime(struct tnt_tm *, struct datetime *): \
Assertion `mday >= 1 && mday <= 31' failed.
```

Closes #8525

NO_TEST=updated fuzzer corpus
NO_CHANGELOG=internal
NO_DOC=internal
parent c2a86b12
No related branches found
No related tags found
No related merge requests found
## bugfix/datetime
* Fixed a bug in `strptime` when the assertion was triggered (gh-8525).
......@@ -627,12 +627,11 @@ tnt_strptime(const char *__restrict buf, const char *__restrict fmt,
}
if (!(flags & FLAG_YDAY) && (flags & FLAG_YEAR)) {
if ((flags & (FLAG_MONTH | FLAG_MDAY)) ==
(FLAG_MONTH | FLAG_MDAY)) {
if ((flags & FLAG_MONTH) != 0 ) {
tm->tm_yday = start_of_month[isleap(tm->tm_year +
TM_YEAR_BASE)]
[tm->tm_mon] +
(tm->tm_mday - 1);
(tm->tm_mday - 1) * !!(flags & FLAG_MDAY);
flags |= FLAG_YDAY;
} else if (day_offset != -1) {
int tmpwday, tmpyday, fwo;
......
07001\ %m%g%W
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment