[BUG] libc/time: strptime() numeric_range upper bound is off by one and accepts invalid dates/times
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- operating-systems
Research direction
Start in libs/libc/time/lib_strptime.c and inspect numeric_range plus the format specifiers that set min and range. Check how the digit loop and upper-bound validation handle the listed values, then run or add focused strptime() checks for each affected specifier. Done means out-of-range values return NULL while the stated valid ranges still parse.
Written by the indexing model from the issue text.
Description
Description / Steps to reproduce the issue
Summary
In libs/libc/time/lib_strptime.c, numeric_range checks *dest > min + range instead of *dest >= min + range:
*dest = 0;
for (i = 1; i <= min + range && isdigit(*s); i *= 10)
{
*dest = *dest * 10 + *s++ - '0';
}
if (*dest < min || *dest > min + range)
{
return NULL;
}
Root Cause
Every specifier jumping to numeric_range sets range to the count of valid values (so the inclusive upper bound is min + range - 1):
%H:min=0, range=24(valid0..23, accepts24)%M:min=0, range=60(valid0..59, accepts60)%S:min=0, range=61(valid0..60, accepts61)%m:min=1, range=12(valid1..12, accepts13->tm_mon = 12)%d/%e:min=1, range=31(valid1..31, accepts32)%I:min=1, range=12(valid1..12, accepts13)%j:min=1, range=366(valid1..366, accepts367)%w:min=0, range=7(valid0..6, accepts7)%u:min=1, range=7(valid1..7, accepts8)%U/%W:min=0, range=54(valid0..53, accepts54)%V:min=1, range=53(valid1..53, accepts54)
Steps to Reproduce
Compile libs/libc/time/lib_strptime.c and parse out-of-range values (Ubuntu 24.04, x86_64, gcc 13.3.0):
strptime("24:00:00", "%H:%M:%S"): glibc=NULL nuttx=MATCH
strptime("12:60:00", "%H:%M:%S"): glibc=NULL nuttx=MATCH
strptime("2026-13-01", "%Y-%m-%d"): glibc=NULL nuttx=MATCH
strptime("2026-01-32", "%Y-%m-%d"): glibc=NULL nuttx=MATCH
strptime("13", "%I"): glibc=NULL nuttx=MATCH
strptime("367", "%j"): glibc=NULL nuttx=MATCH
strptime("7", "%w"): glibc=NULL nuttx=MATCH
strptime("8", "%u"): glibc=NULL nuttx=MATCH
strptime("54", "%U"): glibc=NULL nuttx=MATCH
strptime("54", "%V"): glibc=NULL nuttx=MATCH
Expected Behavior
Use i <= min + range - 1 for the digit loop and reject *dest < min || *dest >= min + range with NULL.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Ubuntu 24.04
NuttX Version
master (cf03942d)
Issue Architecture
[Arch: all]
Issue Area
[Area: Posix]
Host information
Architecture-independent C bug in libs/libc/time/lib_strptime.c. Reproduced on Ubuntu 24.04 x86_64 with gcc 13.3.0.
Verification
- I have verified before submitting the report.
- Dominant language
- C
- Stars
- 4.1k
- Forks
- 1.8k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 881
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/nuttx
-
[BUG] libc/stdlib: lib_checkbase() strips "0x" prefix in base 16 even when no hex digit followsOpenArch: all Area: Posix OS: Linux
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Arch: all Arch: arm Area: Build system OS: Linux Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/nuttx#19435 · 9 comments ·
Maintainers usually reply within 1 day
-
Arch: all OS: Linux Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/nuttx#16249 · 7 comments ·
Maintainers usually reply within 1 day
-
[Bug]: libc/net: getifaddrs() drops and leaks secondary IPv6 addresses and leaves dangling ifa_name and uninitialized netmask/dstaddr pointersPossibly taken @yashgoyal0110 claimed this today. Open
Maintainers usually reply within 1 day
Similar issues
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
389ds/389-ds-base#8251 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ROCm/hrx-system#3628 ·
Maintainers usually reply within 1 day