synctime: fix off-by-one read and write to a read-only buffer (Windows)#20987
synctime: fix off-by-one read and write to a read-only buffer (Windows)#20987vszakats wants to merge 3 commits intocurl:masterfrom
Conversation
Also making the `--synctime` option work. Found by Codex Security
|
augment review |
|
The data libcurl passes to the header function is not supposed to be modified |
🤖 Augment PR SummarySummary: Fixes an off-by-one bug in the Windows 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Pull request overview
Fixes an out-of-bounds read/write in the synctime example’s header parsing on Windows, improving safety and enabling correct --synctime behavior when parsing the HTTP Date: header.
Changes:
- Corrects an off-by-one index when checking/stripping the trailing newline in the received header line.
- Updates the in-buffer NUL termination index used before
sscanf()parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Indeed, even that. It also uses |
|
Giving a try with the local buffer. |
There was a problem hiding this comment.
Pull request overview
Updates the Windows-only synctime libcurl example to address a header callback off-by-one access and avoid writing into the header buffer, while aiming to make --synctime functional again.
Changes:
- Fixes an off-by-one newline check when examining the received
Date:header line. - Adds logic to copy the header line into a local, NUL-terminated buffer before parsing.
Comments suppressed due to low confidence (1)
docs/examples/synctime.c:145
- The header callback buffer passed in
ptris not NUL-terminated (and should not be modified), but this code still callssscanf(field, ...)on that non-terminated buffer. The new localheadercopy is correctly NUL-terminated, but it is never used for parsing; this can still lead to out-of-bounds reads. Parse fromheader(or otherwise ensure NUL-termination within bounds) instead of usingfielddirectly.
char header[100];
size_t len = nmemb < sizeof(header) ? nmemb : sizeof(header) - 1;
memcpy(header, field, len);
header[len] = 0; /* null-terminate local copy */
RetVal = sscanf(field, "Date: %25s %hu %25s %hu %hu:%hu:%hu",
TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear,
&SYSTime.wHour, &SYSTime.wMinute,
&SYSTime.wSecond);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
sscanf use is fine imo. i thought it was fine in the lib as well. |
It's just a tiny example, it's perfectly fine to use sscanf()! |
Also making the
--synctimeoption work.Off-by-one found by Codex Security
Assisted-by: Jay Satiro
sscanf().